While exploring the world of connected things (a.k.a. #IoT) the ESP8266 popped up as an new platform for measuring and sensing data - making Things becoming more relevant. SENSable Things are starting to sense our environment, while feeding data to a cloud the question comes up: what should I read out of the values?
Did you know that VOCs (volatile organic compounds) are emitted by bread? Fresh bread smells not only to us - it has a meaning to VOC sensors, fresh bread smell like value 170! Or can you sense the air in your house - when and how long you should open windows? ...
But let's first dig into the hardware part:
Not going to cover the ESP8266 wiring, there are tons of good tutorials out in the web
Installation of ESP8266 tool chain on Raspberry Pi
Besides the software installation of compiler and tools for flashing the ESP8266 there is also the demand of an appropriate FTDI 3.3V wiring to the ESP8266.
1. ESPtool – python base tool for flashing the ESP8266
wget --no-check-certificate
https://github.com/themadinventor/esptool/archive/master.zip
unzip master.zip
cd esptool-master
sudo python setup.py install
2. LUAtool – libs and samples for coding in LUA language
wget --no-check-certificate
https://github.com/4refr0nt/luatool/archive/master.zip
unzip master.zip
3. NODEmcu – firmware for the EPS8266 supporting LUA coding
wget --no-check-certificate
https://github.com/nodemcu/nodemcu-firmware/archive/master.zip
unzip master.zip
Flash the NODEmcu firmware
Frist make sure the GPIO0 is wired to GND to allow acceptance of new firmware.
Flash the latest firmware to ESP8266:
pi@raspberrypi
~/esp/nodemcu-firmware-master/pre_build/latest $
python /home/pi/esp/esptool-master/esptool.py --port /dev/ttyUSB0 write_flash
0x00000 nodemcu_latest.bin
Connecting...
Erasing
flash...
Writing
at 0x00062000... (100 %)
Leaving...
Done - Unwire GPIO0 before the next step.
Now we download the auto startup LUA script to allow the ESP8266 connection to an access point:
pi@raspberrypi
~/esp/luatool-master/luatool $ python
/home/pi/esp/luatool-master/luatool/luatool.py --port /dev/ttyUSB0 --src
init.lua --dest init.lua --verbose
Set
timeout None
Set
interCharTimeout None
Upload
starting
Stage
1. Deleting old file from flash memory
->file.open("init.lua",
"w") -> ok
->file.close()
-> ok
Stage
2. Creating file in flash memory and write first
line->file.remove("init.lua") -> ok
Stage
3. Start writing data to flash memory...->file.open("init.lua",
"w+") -> ok
->file.writeline([==[print('init.lua
ver 1.2')]==]) -> ok
->file.writeline([==[wifi.setmode(wifi.STATION)]==])
-> ok
->file.writeline([==[print('set
mode=STATION (mode='..wifi.getmode()..')')]==]) -> ok
->file.writeline([==[print('MAC:
',wifi.sta.getmac())]==]) -> ok
->file.writeline([==[print('chip:
',node.chipid())]==]) -> ok
->file.writeline([==[print('heap:
',node.heap())]==]) -> ok
->file.writeline([==[--
wifi config start]==]) -> ok
->file.writeline([==[wifi.sta.config("
SSID
","
passkey
")]==])
-> ok
->file.writeline([==[--
wifi config end]==]) -> ok
->file.writeline([==[wifi.sta.connect()]==])
-> ok
->file.writeline([==[tmr.alarm(1,
1000, 1, function()]==]) -> ok
->file.writeline([==[if
wifi.sta.getip()== nil then]==]) -> ok
->file.writeline([==[print("IP
unavaiable, Waiting...")]==]) -> ok
->file.writeline([==[else]==])
-> ok
->file.writeline([==[tmr.stop(1)]==])
-> ok
->file.writeline([==[print("ESP8266
mode is: " .. wifi.getmode())]==]) -> ok
->file.writeline([==[print("The
module MAC address is: " .. wifi.ap.getmac())]==]) -> ok
->file.writeline([==[print("Config
done, IP is "..wifi.sta.getip())]==]) -> ok
->file.writeline([==[--
dofile ("web.lua")]==]) -> ok
->file.writeline([==[end]==])
-> ok
Stage
4. Flush data and closing file->file.writeline([==[end)]==]) -> ok
->file.flush()
-> ok
->file.close()
-> ok
--->>> All done <<<---
Now we can monitor the NODEmcu console and see output of the LUA script:
pi@raspberrypi
~
$ screen /dev/ttyUSB0 9600
NodeMCU
0.9.5 build 20150214 powered by Lua
5.1.4
lua:
cannot open init.lua
>
As
the init.lua has not yet started either do an RESET, POWER ON/OFF, or enter
dofile(“init.lua”) to execute the script.
NodeMCU
0.9.5 build 20150214 powered by Lua
5.1.4
init.lua
ver 1.2
set
mode=STATION (mode=1)
MAC: 18-FE-34-FE-34-0C
chip: 16659468
heap: 17184
>
IP unavaiable, Waiting...
IP
unavaiable, Waiting...
ESP8266
mode is: 1
The
module MAC address is: 1A-FE-34-FE-34-0C
Config
done, IP is 192.168.2.115
>
Done – ESP8266 is now connected to the access point showing its DHCP IP address.
Comments