In the previous post, I implemented a simple counter with serial output and today I improved it. The main reason I purchased the ESP8266 module in the first place was to get WiFi for cheap, so I wanted to try out the WiFi capabilities. The resulting sketch is still a counter, but instead of publishing the count via the serial interface, it connects wirelessly to a database and publishes the count there.
To begin with, I needed a simple database that I could access via HTTP. Redis is a simple key/value type database, but it doesn’t have an HTTP interface. I found Webdis “A fast HTTP interface for Redis”. To set things up quickly, I found that someone had already put everything together and published a Docker image on DockerHub. So, through the magic of Docker, all I had to do to get Redis and Webdis up and running on my computer was run this magic command:
docker run -d -p 7379:7379 -e LOCAL_REDIS=true anapsix/webdis
I then wrote a sketch that would publish to my new database:
#include <ESP8266WiFi.h>
const char* ssid = "name of wifi network";
const char* pass = "wifi network password";
const char* ip = "192.168.1.35";
const int port = 7379;
int count = 0;
void setup() {
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
}
}
void loop() {
delay(5000);
WiFiClient client;
client.connect(ip, port);
String url = String("/SET/count/") + count++;
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + String(ip) + "\r\n" +
"Connection: close\r\n" +
"Content-Length: 0\r\n" +
"\r\n");
}
Basically, it connects to the wifi network (ssid) using the provided password (pass) and then publishes the count to the database (located at ip). It publishes the new count value every five seconds.
To verify that it was working, I simply plugged this URL into my web browser :
192.168.1.35.7379/GET/count
It returns the current value of count:

So now I can not only program my new toy, but also use some of its wireless capabilities. It’s not useful, but it is a good step to learning how to use the ESP8266.


The nostalgia of coding and playing 
I have long been familiar with Tolkien’s The Hobbit and also The Lord of the Rings, but remained mostly ignorant of his other works apart from a 1982 print of The Silmarillion which somehow ended up in my collection. This past Mother’s Day my wife received a couple volumes of other Tolkien tales and I noticed in one that among the “other books by the author” it listed The Adventures of Tom Bombadil and was intrigued enough to order it in a volume combined with Farmer Giles of Ham.
Back in the magical decade known as the 90’s I got my first graphing calculator. It was one of the Casio FX-7000 variants–I don’t recall which one exactly, but I do clearly remember that it had 422 bytes of memory to be used by programs. While I wrote some programs to do mathy stuff, most programs were games. I think the first game I wrote for the calculator was a number guessing game where the game would generate a random number and the player would enter guesses and be told it the actual number was higher or lower. There were various other games along the same vein. Then I started coding with a friend and things got “Dangerous”.
The first book is a 45 year old Le Petit Prince in the original French. I believe I stole it from my parents’ home and it most likely was previously claimed by my mother or sister. I remember as a kid reading an English translation (which my parents probably still have along with another French copy) and enjoying the story while marveling that my parents and sister could read it. Later when I was studying French I read portions of the text and experienced the story in new ways because I was forced to slow down (and often read it aloud).
When I saw the word “Triby”, my mind jumped to a classic Star Trek episode and I imaged Captain Kirk and a bunch of fuzzy things. A quick search revealed that those are “Tribbles” and that the Triby is very different, but the similarity in name grabbed my attention enough that I put forth to answer the question, “What’s a Triby?”
To me the Triby looks like a toy radio for children. It has a magnet on the back so that it can be attached to a fridge. The buttons are also have a toy-ish appearance. The screen is a small e-ink display–probably to reduce power consumption (the battery lasts about two days on a charge). The neatest physical aspect of the Triby is the mechanical flag that pops out of the side when a new message is received.
