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.


SumnerBoy

2079 posts

Uber Geek
+1 received by user: 306

ID Verified
Lifetime subscriber

#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
333 posts

Ultimate Geek
+1 received by user: 43


  #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?

 

 




SumnerBoy

2079 posts

Uber Geek
+1 received by user: 306

ID Verified
Lifetime subscriber

  #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
333 posts

Ultimate Geek
+1 received by user: 43


  #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?




SumnerBoy

2079 posts

Uber Geek
+1 received by user: 306

ID Verified
Lifetime subscriber

  #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
+1 received by user: 1041

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
+1 received by user: 1041

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








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.