fab-lab.eu
Published

Tame the Beast: Ultra-Low Power #ESP8266 Thing

Quickstart guide to start with #NodeMCU on the #ESP8266 Thing, hacking to become a ultra-low power, solar power only driven #SENSableTHING

IntermediateFull instructions provided72,108
Tame the Beast: Ultra-Low Power #ESP8266 Thing

Things used in this project

Hardware components

SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
SparkFun FTDI Basic Breakout - 3.3V
SparkFun FTDI Basic Breakout - 3.3V
×1
Lithium Ion Cylindrical Battery - 3.7v 2200mAh
High Power - check below for the solar power version!
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
LiPo battery 200mAh or 400mAh
Low Power - the solar power version needs only a smaller battery
×1
0.5W solar panel
Low Power - the solar power version needs of course an solar panel 5.5V max., 110mA
×1

Software apps and online services

NodeMCU firmware
NodeMCU firmware

Story

Read more

Schematics

Modified LiPo charger - input from solar panel

Code

init.lua

Lua
init script will be started by autostart of nodemcu, scripted in LUA language, change the SSID and passkey according to your Wifi AP, uncomment dofile ("thing.lua") if you want to autostart thing.lua after next boot
print('init.lua ver 1.2')
wifi.setmode(wifi.STATION)
print('set mode=STATION (mode='..wifi.getmode()..')')
print('MAC: ',wifi.sta.getmac())
print('chip: ',node.chipid())
print('heap: ',node.heap())
-- wifi config start
wifi.sta.config("SSID","passkey")
-- wifi config end
wifi.sta.connect()
 tmr.alarm(1, 1000, 1, function()
  if wifi.sta.getip()== nil then
  print("IP unavaiable, Waiting...")
 else
  tmr.stop(1)
 print("ESP8266 mode is: " .. wifi.getmode())
 print("The module MAC address is: " .. wifi.ap.getmac())
 print("Config done, IP is "..wifi.sta.getip())
 -- dofile ("thing.lua")
 end
end)

thing.lua

Lua
sending analog sensor data to ThingSpeak cloud for visualization, replace YOURWRITEKEY with your ThingSpeak write key
port = 80

function sendData()

t1=adc.read(0)
print("VOC:"..t1.." C\n")

-- conection to thingspeak.com
print("Sending data to thingspeak.com")
conn=net.createConnection(net.TCP, 0) 
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149') 
conn:send("GET /update?key=YOURWRITEKEY&field1="..t1.." HTTP/1.1\r\n") 
conn:send("Host: api.thingspeak.com\r\n") 
conn:send("Accept: */*\r\n") 
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n
")
conn:send("\r\n")
conn:on("sent",function(conn)
                      print("Closing connection")
                      conn:close()
                  end)
conn:on("disconnection", function(conn)
          print("Got disconnection...")
  end)
end

-- send data every X ms to thing speak
tmr.alarm(0, 10000, 1, function() sendData() end )

init.lua - the power test cycle LUA

Lua
This trick helps to give a little time buffer in case you do want to flash a new LUA file ... without this you need to flash the nodeMCU code again to release the init.lua script ...
FileToExecute="pw.lua"
l = file.list();
for k,v in pairs(l) do
  if k == FileToExecute then
    print("*** You've got 5 sec to stop timer 0 ***")
    tmr.alarm(0, 5000, 0, function()
      print("Executing ".. FileToExecute)
      dofile(FileToExecute)
    end)
  end
end

pw.lua - the power test cycle LUA

Lua
just does an deep sleep every 60 sec ... here is the place for ESP8266 code to be executed during wake up ... we moved from 60 sec now to 300 sec sleep (5 minutes)
interval = 60000000
node.dsleep(interval-tmr.now())

Credits

fab-lab.eu

fab-lab.eu

22 projects • 275 followers
Maker!

Comments