Flash ESP8266 Witty Cloud Board with 6 Wires

Witty Cloud board is an ESP8266 development board that has a unique two-PCB design: the top PCB carries the ESP8266 microcontroller and an AMS1117 voltage regulator, and the bottom PCB carries a CH340G USB-serial chip. The top PCB can operate independently. It has a pair of 8-pin male headers that expose ESP8266's GPIO pins, which can be used to control peripherals such as LEDs and buttons. The bottom PCB is needed only for flashing the ESP8266. It has a pair of 8-pin female headers. The top PCB should be inserted into the bottom PCB when the firmware is being flashed from a computer, or when we want to use Arduino's serial monitor.

Sometimes, we may want to simultaneously connect ESP8266's GPIO pins to peripherals, and keep the ability of flashing the firmware or monitoring the serial console from a computer. Can we achieve that?

From electric point of view, when the male headers on the top PCB are inserted into the female headers on the bottom PCB, each of the 16 pins on one PCB is connected to the corresponding pin on the other PCB via a wire. Thus, if we connect the two PCBs with 16 jumper wires, everything should work.

But it's tedious to connect 16 wires every time. Can we connect the two PCBs with less jumper wires? Let me find out.

I started with four wires:

Understanding the Photoresistor on Witty Cloud Board

One of my favorite electronic elements is the photoresistor, an element whose resistance decreases with increasing incident light intensity. I played with a photoresistor as part of an electronic building blocks toy kit when I was in elementary school, and made a geocaching trackable out of that experience. But I want a deeper understanding of the photoresitor: what's the correlation between its conductivity and the light intensity?

photoresistor circuit symbol

Recently I acquired some Witty Cloud boards. This board is built around an ESP8266 microcontroller; a photoresistor (aka Light Dependent Resistor, LDR) is connected to the analog input port of the ESP8266. With one line of code in Arduino (analogRead(A0)), we could read the light intensity as a number between 0 and 1023. However, what's the unit of this number, and how does it translate to the standard units such as lumens?

I couldn't find any formula for this translation, because it does not exist. Adafruit explains photoresistor readings nicely:

The readings taken are not in any useful units of light intensity. Photoresistors are not carefully calibrated sensors. If you wanted to make a light meter, with absolute measurement of light intensity in meaningful units, you would need to create a lookup table that related readings with readings taken from a properly calibrated light meter.

First Impression on ESP8266 Witty Cloud Board

I get addicted to ESP8266 ever since Losant sent me a builder kit which includes an Adafruit Feather HUZZAH. Witty Cloud GitWits is one of the cheapest ESP8266 device you can get on the market. It has a microUSB port with USB-Serial interface, which means no soldering! The board also contains an RGB LED and a button, which allows me to use it without a breadboard. So, I decide to go for it!

I ordered the Witty Cloud board from AliExpress, a Chinese E-commerce site. Ordering experience isn't so good. For some reason, they cancelled my order due to "difficulty in verifying payment". I had to upload a scanned copy of my passport and credit card statement, before they would ship my items. After getting past those non-technical steps, the Witty Cloud development board is in my mailbox 2 weeks later. There's no doubt I'm excited!

Appearance

The board is very small and lightweight. Its dimension is 31mm x 30mm x 18mm. Its weight is roughly the same as an Adafruit Feather HUZZAH.

Witty Cloud board has two PCBs connected via a pair of 8-pin headers.

Monitor Uptime of a Losant Device

Losant is a simple and powerful IoT cloud platform. Sensor devices, such as the Losant Builder Kit, can connect to their MQTT broker over the public Internet, and report state in real time. Based on those state reports, the software running in the cloud (call "workflows") can take actions such as sending an alert over email or text message, or deliver a command to be executed on an actuator device over MQTT.

One important question to ask is: how stable is this system? There are many elements in this system that can fail:

  • Losant MQTT broker
  • workflows in the cloud
  • connected device (sensor or actuator)
  • power supply to the connected device
  • the Internet connection

Hopefully, the good folks at Losant has deployed enough redundancy for their MQTT broker and machines to execute workflows, and the user is careful enough when modifying the workflows. A failure is more likely to occur in the connected device, its power supply, or Internet connection. Failure in any of these three elements will result in the device being disconnected from the Losant MQTT broker. Thus, we can find out how stable the system is from the cloud end: monitor MQTT connection from a workflow.

Brent Crawford has designed a workflow to alert the owner when a device has been offline for more than 10 minutes. While it's useful for a device deployed in the field, it's unnecessary for me to receive alerts because my device is right across the room and I can just glance at an LED that indicates its connectivity. I'm more interested in the history of device uptime.

LosantPingPong: End-to-end Losant Connectivity Test

Losant is a simple and powerful IoT cloud platform. The platform provides a MQTT broker that sensor devices can connect to and report state in real time; the reported states are stored in the cloud, and can be visualized in several formats.

Recently, Losant sent me a Builder Kit which contains an ESP8266 WiFi chip on Adafruit Feather Huzzah, a TMP36 temperature sensor, and some other components. Following the official instructions, 1.5 hours later, my room temperature shows up on a webpage.

I'm excited, and I decide to leave it running continuously so that I can monitor the activities of @TheTucsonHeat. However, Losant platform shows the device as "offline" from time to time, and sometimes it never comes back online unless I press the hard-reset button. This is mostly because of the bad WiFi in my apartment: 1000ms huge delay, 10% or more packet loss, etc. Since MQTT is based on TCP, it's severely affected. To make things worse, our WiFi connects to the Internet through two levels of Network Address Translation (NAT) gateways; it seems that the ESP8266 sometimes is unable to detect the TCP connection to Losant broker is broken, and thus does not take recovery actions.

As a computer networking student, the first thing coming through my mind is the end-to-end principle: the reliability of an application should be ensured by the end hosts, not by the network. To test whether my temperature sensor remains connected to Losant, I should send a message to the Losant platform, and let the platform send back a reply. And that's the idea of LosantPingPong: an end-to-end connectivity test between a connected device and the Losant platform.

LosantPingPong protocol

How to Survive a Weekend Offline?

I'm a heavy smartphone user. I read emails, access Twitter, check in on Swarm/Foursquare, watch YouTube, and look at weather forecast, multiple times a day. I use smartphones so much that my primary phone, the Nexus 5, needs to be charged 2~3 times per day, and I am reluctant to stay in places without free WiFi.

But, everything is changing in the past weekend: I joined a camping trip to Grand Canyon National Park. There is no electricity. There is no cellular signal, because national parks do not want cell towers to ruin the beautiful landscape. There is no WiFi, except in the cafeteria which we may or may not visit. Without electricity, I cannot keep my smartphones charged. Without cellular or WiFi, I cannot receive emails, access Twitter, check in on Swarm/Foursquare, watch YouTube, or use weather forecast apps. How can I survive the weekend in the national park, without electricity or Internet access?

Preparation

Internet access is unavailable, but it's not the only way to communication with the outside world. On many smartphones, there's a forgotten app called the FM radio, which allows you to receive information without Internet access or cellular signal. Therefore, I packed an old smartphone, the T-Mobile Comet, which has an FM radio tuner. This would allow me to listen to the weather forecast, and maybe some news and music.

My camping trip is a short one: we depart on Friday and return on Sunday. The lack of electricity can be solved by a few USB PowerBanks. I brought two USB PowerBanks, which contain a total of 12800mAh of electricity, enough to charge the Nexus 5 five times, or the T-Mobile Comet ten times.

My Experience at Hack Arizona 2016

Hack Arizona is the largest collegiate hackathon in southwestern United States. I attended Hack Arizona 2016 and had a great experience, and I want to share what I experienced during this event.

Why I didn't attend in 2015

I heard about Hack Arizona when it started in 2015, but I decided against attending last year because 37 sleepless hours is harmful for health and won't produce high quality project.

Many of my friends went in 2015, and they shared their experiences and showed me their projects. The situation sounds less scary than I imagined:

  • Although you are provided enough coffee and Red Bull energy drinks to stay up, you are permitted to leave and re-enter at anytime, and you can sleep in the venue as well.
  • There's free food, and it's not just pizza.
  • Projects aren't of poor quality.

parallelize.sh: run commands in parallel with bash

Recently I'm doing some heavy research work. One part of my work involves invoking a simulation script with different inputs and parameters and then an analysis script to analyze the simulation output.

At first, this is an easy bash loop:

(
  echo 3 11
  echo 3 11
  echo 5 19
  echo 5 19
) | while read -r -a L; do
  X=${L[0]}
  Y=${L[1]}
  python2 simulation.py --x=$X --y=$Y < input.tsv > $X-$Y.simulation.log
  gawk -f analysis.awk $X-$Y.simulation.log > $X-$Y.analysis.tsv
done

The loop works fine, but it takes too long time when the input gets larger, because scripts are running sequentially. Since we have a big server with 32 CPU cores, can I run the scripts in parallel?

So I wrote this nifty little script, parallelize.sh:

Share Dropbox between VirtualBox Host and Guest

My laptop comes with Windows, like most other laptops in the market. But as a computer science student, I need to use Linux from time to time. The laptop manufacturer advised me not to install Linux directly on this laptop. Although this would not void my warranty, they would not provide technical support or supply device drivers if I install Linux. Therefore, I turned into VirtualBox, a hypervisor that allows me to run Linux in a virtual machine, alongside the Windows installation.

I'm also a heavy user of Dropbox, a file hosting service that can synchronize my documents among all my device. I have Dropbox clients installed everywhere, including the Windows of this laptop, and the Linux virtual machine. When I edit a file, the Dropbox client uploads this file to the cloud, and then the Dropbox clients on all other devices download the file from the cloud.

One day, there's a congestion on my apartment's WiFi hotspot, and I notice that the Dropbox synchronization between Windows and the Linux virtual machine is having significant delay: every update travels a long way to the cloud, and then comes back. I also realize that, in my setup, the entire Dropbox contents are duplicated twice: it has one copy in Windows, and another copy in Linux virtual machine. Although having multiple copies is usually a good thing because you have more redundancy, having multiple copies on the same hard drive is not useful. Can I eliminate the synchronization delay and the redundant copy?

VirtualBox Shared Folder

VirtualBox has a nifty feature, shared folders, which allows files of the host system to be accessed within a guest system. In my setup, I could use this feature to access the Dropbox on Windows within the Linux virtual machine.

NDN hackathon proposal: Clock setup for devices without hardware RTC

This is one of the proposals I submitted to the first Named Data Networking hackathon.

Motivation

Certain cheap devices, most notably the Raspberry Pi, comes without a hardware Real Time Clock (RTC), and relies on Network Time Protocol (NTP) to setup its clock during system boot. NTP is an IP based protocol which would not work in a pure NDN network. It's necessary to define an NDN based protocol for clock setup.

Approach

protocol design and demo system