Using Gmail with OAUTH2 in Linux and on an ESP8266

One of the tasks I dread is configuring a web server to send email correctly via Gmail. The simplest way of sending emails is SMTP, and there are a number of scripts out there that provide a simple method to send mail that way with a minimum of configuration. There’s even PHP mail(), although it’s less than reliable.

Out of the box, Gmail requires OAUTH2 for authentication and to share user data, which has the major advantage of not requiring that you store your username and password in the application that requires access to your account. While they have an ‘allow less secure apps’ option that allows SMTP access for legacy products like Microsoft Outlook, it just doesn’t seem like the right way forward. Google documents how to interact with their API with OAUTH2, so why not just use that instead of putting my username and password in plaintext in a bunch of prototypes and test scripts?

Those are the thoughts that run through my head every time this comes up for a project, and each time I’ve somehow forgotten the steps to do it, also forgotten to write it down, and end up wasting quite a bit of time due to my own foolishness. As penance, I’ve decided to document the process and share it with all of you, and then also make it work on an ESP8266 board running the Arduino development environment.

Continue reading “Using Gmail with OAUTH2 in Linux and on an ESP8266”

Statistics and Hacking: A Stout Little Distribution

Previously, we discussed how to apply the most basic hypothesis test: the z-test. It requires a relatively large sample size, and might be appreciated less by hackers searching for truth on a tight budget of time and money.

As an alternative, we briefly mentioned the t-test. The basic procedure still applies: form hypotheses, sample data, check your assumptions, and perform the test. This time though, we’ll run the test with real data from IoT sensors, and programmatically rather than by hand.

The most important difference between the z-test and the t-test is that the t-test uses a different probability distribution. It is called the ‘t-distribution’, and is similar in principle to the normal distribution used by the z-test, but was developed by studying the properties of small sample sizes. The precise shape of the distribution depends on your sample size. Continue reading “Statistics and Hacking: A Stout Little Distribution”

Statistics and Hacking: An Introduction to Hypothesis Testing

In the early 20th century, Guinness breweries in Dublin had a policy of hiring the best graduates from Oxford and Cambridge to improve their industrial processes. At the time, it was considered a trade secret that they were using statistical methods to improve their process and product.

One problem they were having was that the z-test (a commonly used test at the time) required large sample sizes, and sufficient data was often unavailable. By studying the properties of small sample sizes, William Sealy Gosset developed a statistical test that required fewer samples to produce a reasonable result. As the story goes though, chemists at Guinness were forbidden from publishing their findings.

So he did what many of us would do: realizing the finding was important to disseminate, he adopted a pseudonym (‘Student’) and published it. Even though we now know who developed the test, it’s still called “Student’s t-test” and it remains widely used across scientific disciplines.

It’s a cute little story of math, anonymity, and beer… but what can we do with it? As it turns out, it’s something we could probably all be using more often, given the number of Internet-connected sensors we’ve been playing with. Today our goal is to cover hypothesis testing and the basic z-test, as these are fundamental to understanding how the t-test works. We’ll return to the t-test soon — with real data. Continue reading “Statistics and Hacking: An Introduction to Hypothesis Testing”

Hackers vs. Mold: Building a Humidistat Fan

Having a mold problem in your home is terrible, especially if you have an allergy to it. It can be toxic, aggravate asthma, and damage your possessions. But let’s be honest, before you even get to those listed issues, having mold where you live feels disgusting.

You can clean it with the regular use of unpleasant chemicals like bleach, although only with limited effectiveness. So I was not particularly happy to discover mold growing on the kitchen wall, and decided to do science at it. Happily, I managed to fix my mold problems with a little bit of hacker ingenuity.

Continue reading “Hackers vs. Mold: Building a Humidistat Fan”

Shockingly, DARPA’s Brain Stimulator Might Not be Complete Nonsense

Where does your mind jump when you hear the mention of electroshock therapy? The use of electrical current to treat various medical conditions has a long and controversial history. Our fascination with the medical applications of electricity have produced everything from the most alarming of patent medicines to life-saving devices like pacemakers and the Automatic External Defibrillator.

The oldest reference I could find is the use of the torpedo fish to allegedly cure headaches, gout, and so on in 43 CE. Incidentally, Torpedo torpedo is an awesome species name.

Dosage: Apply live fish as needed to face? Source

Much more recently, there has been interest in transcranial direct current stimulation (tDCS). In essence, it’s a technique by which you pass an electrical current (typically about 2 milliamps) between strategically positioned electrodes on your head. The precise reason to do this is a bit unclear; different journal articles have suggested improvements in cognition, learning, and/or the potential treatment of various diseases.

I think most of us here spend a lot of time studying. The idea that a simple, noninvasive device can accelerate that is very attractive. We’ve covered a few people building their own such devices.

Unfortunately, what we want to be true is irrelevant. Superficially, this looks like a DARPA-funded panacea with no clearly established mechanism of action. Various commercial products are being sold that imply (but as usual, don’t directly state) that tDCS is useful for treating pretty much everything, with ample use of ‘testimonials’.

While tDCS can be prescribed by a physician in some countries to complement a stroke rehabilitation regime, for off-label purposes you may as well just go apply a fish to your face. Let’s dig into the literature and products that are out there and see if we can find the promise hiding amidst the hype.

Continue reading “Shockingly, DARPA’s Brain Stimulator Might Not be Complete Nonsense”

How Pure is this Cup of Joe? Coffee, Conspiracy, and Citizen Science

Have you ever thought about coffee purity? It’s more something you’d encounter with prescription or elicit drugs, but coffee is actually a rather valuable commodity. If a seller can make the actual grounds go a bit further by stretching the brew with alternative ingredients there becomes an incentive to cheat.

If this sounds like the stuff rumors are made of, that’s because it is! Here in Ho Chi Minh City there are age-old rumors a coffee syndicate that masterfully passes off adulterated product as pure, high-grade coffee. Rumors are one thing, but the local media started picking up on these suspicions and that caught my attention. I decided to look to simple chemistry to see if I could prove or disprove the story.

What we want to investigate is whether price and coffee purity are related. If they are, then after accounting for the effect of price, we will want to know whether proximity to the market where artificial coffee flavoring is sold has an effect on coffee purity.

Continue reading “How Pure is this Cup of Joe? Coffee, Conspiracy, and Citizen Science”

Review: IoT Data Logging Services with MQTT

For the last few months, I had been using Sparkfun’s Phant server as a data logger for a small science project. Unfortunately, they’ve had some serious technical issues and have discontinued the service. Phant was good while it lasted: it was easy to use, free, and allowed me to download the data in a CSV format. It shared data with, which at the time was a good solution for data visualization.

While I could continue using Phant since it is an open-source project and Sparkfun kindly releases the source code for the server on Github, I thought it might be better to do some research, see what’s out there. I decided to write a minimal implementation for each platform as an interesting way to get a feel for each. To that end, I connected a DHT11 temperature/humidity sensor to a NodeMCU board to act as a simple data source.

Continue reading “Review: IoT Data Logging Services with MQTT”