/nodemcu_sonoff

Some nodemcu based to run sonoff wifi enabled plugs through MQTT

Primary LanguageLuaGNU General Public License v3.0GPL-3.0

nodemcu_sonoff

Some nodemcu based code to run sonoff wifi enabled plugs through MQTT The button on the device can also be used to toggle the state of the plug

Main difference with jesstr (https://github.com/jesstr/nodemcu_sonoff) fork :

  • on this one : power status and command are available in the same topic /cmd/power (useful when multiple remotes should stay in sync). One more command : "/cmd/status" which returns the state on top of jesstr's timed version
  • on jesstr's one : command is on /cmd/power and status on /state/power

How To

Clone the repo Symlink esptool.py and luatool.py (available on github) in the main repo copy default_config.py, rename it to config.py and update it according to your needs execute install.sh

Files

  • config.lua : as its name implies
  • init.lua : runs the wifi connection and launches ota and broker modules
  • http.lua : web server (http) and over the air updates module
echo -e "**LOAD**\npage.tmpl" | cat -  page.tmpl | socat -u stdin TCP:ipaddress:80 -- updates the page.tmpl file on device
echo "**RESTART**" | socat -u stdin TCP:ipaddress:80 -- restart esp8266
  • mqtt.lua : mqtt client module
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/power" -m "on" -- turn plug on
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/power" -m "off" -- turn plug off
mosquitto_pub -h "myMQTTserver" -t "/myMQTTpath/myClientID/cmd/status" -m "" -- immediately returns status in /myMQTTpath/myClientID/state/#

Sonoff pin layout and GPIOs stolen from Pete and the community
Wifi connection loop stolen from marcelstoer/wifi-watch.lua
nodemcu firmware generated with Marcel's NodeMCU custom build machine (just add MQTT to the standard module selection)
Correction of shameful bugs, multi-wifi enabled, install script and other stuff by jesstr, thank you !