Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


#195626 27-Apr-2016 12:00
Send private message

For anyone tinkering with the ESP8266/NodeMCU/Wemos devices, and are interested in MQTT, you should definitely check out the open source framework called Homie. This is a very well written and stable framework you can deploy to your device and it will handle all the WIFI and MQTT setup and connections etc. All you have to do is worry about reading your sensors etc.

 

One of the best things about the ESP8266 and Homie is that it supports OTA (over-the-air) updates. So you can deploy your devices and then upgrade the firmware without needing any physical access to the device - a huge advantage IMO!

 

In order to facilitate these OTA updates myself and another chap (JP Mens) have written a python based _Homie OTA Server_ which allows you to maintain an inventory of firmware versions, keep track of your Homie devices, and schedule OTA updates.

 

    https://github.com/jpmens/homie-ota/

 

Just thought some of you might find this useful so figured I would share it here.

 

 


Create new topic
russelo
328 posts

Ultimate Geek


  #1542715 27-Apr-2016 12:21
Send private message

Thanks for starting up this thread.

 

I've been tinkering with with Homie and ESP8266 for a couple days now but I couldn't configure it to connect to my wifi.

 

I loaded the basic sketch and configure the wifi connection using this method:

 

http://marvinroger.github.io/homie-esp8266/

 

But I kept getting invalid name error.  It looks like the name field of the JSON configuration is empty.

 

How do you guys configure the wifi connection?

 

 




  #1542719 27-Apr-2016 12:30
Send private message

I have a special sketch I use to load the config onto the device first, which writes it to the SPIFFS. This will also format the SPIFFS first so make sure there is nothing on there you want to keep.

 

After this is loaded you can load a standard Homie sketch. When Homie starts up it will read the /homie/config.json from the SPIFFS and connect to your WIFI and MQTT broker.

 

And once you have a working Homie sketch loaded, you can unplug from your PC and all future firmware updates can be handled by homie-ota.

 

 

 

[code]

 

#include <ArduinoJson.h>
#include "FS.h"

 

bool saveConfig()
{
StaticJsonBuffer < 1050 > jsonBuffer;
JsonObject & json = jsonBuffer.createObject();

 

json["name"] = "Device 01";
json["device_id"] = "device-01";

 

JsonObject & wifi = json.createNestedObject("wifi");
wifi["ssid"] = "...";
wifi["password"] = "...";

 

JsonObject & mqtt = json.createNestedObject("mqtt");
mqtt["host"] = "mqtt.home";
mqtt["port"] = 1883;
mqtt["ssl"] = false;
mqtt["auth"] = true;
mqtt["username"] = "...";
mqtt["password"] = "...";
mqtt["base_topic"] = "/homie/";

 

JsonObject & ota = json.createNestedObject("ota");
ota["enabled"] = true;
ota["ssl"] = false;
ota["host"] = "web01.home";
ota["port"] = 9080;
ota["path"] = "/homie-ota";

 

json.printTo(Serial);

 

File configFile = SPIFFS.open("/homie/config.json", "w");
if (!configFile) {
Serial.println("Failed to open config file for writing");
return false;
}
json.printTo(configFile);
return true;
}

 

void setup()
{
Serial.begin(115200);
Serial.println("");
delay(1000);

Serial.println("Formatting FS...");
SPIFFS.format();

 

Serial.println("Mounting FS...");
if (!SPIFFS.begin()) {
Serial.println("Failed to mount file system");
return;
}

saveConfig();
}

 

void loop()
{
}

 

[/code]

 

 


russelo
328 posts

Ultimate Geek


  #1543089 27-Apr-2016 22:38
Send private message

It worked. Thanks a lot.

 

Just wondering how you arrived using this method?

 

The standard suggested methods by Homie didn't work for you either?




  #1543092 27-Apr-2016 22:40
Send private message

JP Mens, the chap who wrote homie-ota with me, devised it.

ubergeeknz
3344 posts

Uber Geek

Trusted
Vocus

  #1543117 28-Apr-2016 00:42
Send private message

Timely, I'm just part way into building an IoT thing with an ESP8266 and was planning to use MQTT so I can use Amazon IoT... the OTA updates definitely appeal.  Will take a gander - thanks!


ubergeeknz
3344 posts

Uber Geek

Trusted
Vocus

  #1543142 28-Apr-2016 01:20
Send private message

For the sensor I'm building, I intend to have it take a reading, dispatch the reading, and then enter deep sleep to save power (it will be powered by a small solar panel and rechargeable battery so it needs to be as frugal as possible).

 

I have been reading the API documentation, but could not determine any way to tell whether homie has sent and retrieved its MQTT message(s) yet, indicating it is OK to go back to sleep until the next reading is due. If I instead reached a timeout limit indicating it had failed to do so, the device might do a shorter sleep.

 

Would appreciate any thoughts, if you have the time :)  Thanks!


Create new topic





News and reviews »

Air New Zealand Starts AI adoption with OpenAI
Posted 24-Jul-2025 16:00


eero Pro 7 Review
Posted 23-Jul-2025 12:07


BeeStation Plus Review
Posted 21-Jul-2025 14:21


eero Unveils New Wi-Fi 7 Products in New Zealand
Posted 21-Jul-2025 00:01


WiZ Introduces HDMI Sync Box and other Light Devices
Posted 20-Jul-2025 17:32


RedShield Enhances DDoS and Bot Attack Protection
Posted 20-Jul-2025 17:26


Seagate Ships 30TB Drives
Posted 17-Jul-2025 11:24


Oclean AirPump A10 Water Flosser Review
Posted 13-Jul-2025 11:05


Samsung Galaxy Z Fold7: Raising the Bar for Smartphones
Posted 10-Jul-2025 02:01


Samsung Galaxy Z Flip7 Brings New Edge-To-Edge FlexWindow
Posted 10-Jul-2025 02:01


Epson Launches New AM-C550Z WorkForce Enterprise printer
Posted 9-Jul-2025 18:22


Samsung Releases Smart Monitor M9
Posted 9-Jul-2025 17:46


Nearly Half of Older Kiwis Still Write their Passwords on Paper
Posted 9-Jul-2025 08:42


D-Link 4G+ Cat6 Wi-Fi 6 DWR-933M Mobile Hotspot Review
Posted 1-Jul-2025 11:34


Oppo A5 Series Launches With New Levels of Durability
Posted 30-Jun-2025 10:15









Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.