Introduction: Program Sonoff Using Blockly
Sonoff is a cheap ($4.85) wireless component built by http://www.iteadstudio.com.
It is also hackable, that is you can flash it with your own program.
This instructable will show you how to create you own .lua program, using blockly, that can be loaded onto the sonoff.
To wire up a sonoff for programming you can follow one of the many online tutorials such as the one located here: http://tech.scargill.net/itead-slampher-and-sonoff
To flash the sonoff with an operating system I use nodemcu_flasher32bit.exe (attached), this operating system is contained in the nodemcu_float_0.9.6-dev_20150704.bin file (attached). The single sonoff momentary depress switch should be pressed and power cycled to place the sonoff in program mode.
Once the operating system is loaded, your program made with blockly can be loaded using LuaLoader (attached).
Step 1: Using Blockly to Create Custom .lua Programs
Press the load button and enter: "sonoff.xml" this will load an example solution I created for the sonoff that turns the relay (connected to gpio 6) on or off.
You can then manipulate the blocks and look at the lua tab to see the created lua code.
Copy and paste this .lua code to an init.lua file and upload this to the sonoff using lua_loader
Step 2: Testing Out the Sonoff Using the Raspberry Pi
The sonoff needs to be commanded on or off. I also created a raspberry pi solution (using php and apache web server) to allow a person to configure and command a set of esp8266 based devices (such as the sonoff). To test the sonoff, download the 2 gb zipped .img file located here: https://mega.nz/#!bkJmUbJA!DRGMBhhNsRee5qcLjW7xvRkY9QK5cPCJxlUzxsGR2aU
After download, unzip and write the .img file to a 8gb mini sd (SANDisk) card. Use Win32DiskImager.exe(https://sourceforge.net/projects/win32diskimager/) to write the .img file to the mini sd card.
When placed in a raspberry pi model 3 the pi will create a wireless access point with ssid="pipboy2000" and password="" which can be logged in to by your laptop. Then open a browser to 172.24.1.1/Paulware to access the sonoff.