Basic R2 |
I purchased a basic model (Sonoff Basic R2) for ~$7.00 and begin experimenting with different code libraries freely available on the web. The goal was to turn an external device hooked to the Sonoff on and off at a predetermined time each day. I found a library that contained code for accessing an NTP (Network Time Protocol) server. This allowed me to fetch the current time off the web. Next, I hard coded specific times for turning my device on and off. The drawback to using fixed times is they can only be changed by altering the program and recompiling it. For now this will work fine, but down the road I might use an app on my Smartphone to program an on time and off time on the fly. This, of course would require a one-time modification to the program.
In order to load (flash) the compiled code onto the Sonoff board I needed an interface between the computer and the ESP chip. This was because the USB end uses 5.0V while the ESP circuitry uses 3.3V. I purchased an FTDI based USB to TTL interface board from Amazon, transferred my code and was up and running in no time.
Neat little devices.
Update (June 2019)
After using my Sonoff for a while with hardcoded on/off times embedded in the firmware, I finally decided to experiment with the Blynk app on my Smartphone to allow for dynamic changes to the on/off parameters. Blynk comes with coding examples already written for specific applications so I used one suited for my needs and simply copied and pasted the appropriate sections into my existing program. I also made sure to store any changes to the on/off parameters into non-volatile memory to ensure the Sonoff would work when power was lost and then restored. After loading the newly compiled code into the Sonoff chip, it ran w/o any hiccups. So easy! Now I can change the on/off times if needed w/o reprogramming the chip and the Sonoff will respond accordingly.
No comments:
Post a Comment