LowPowerLab Forum

Hardware support => Projects => Topic started by: rfmesp on July 12, 2016, 09:14:06 PM

Title: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: rfmesp on July 12, 2016, 09:14:06 PM
Here is my first try at a RFM69 MQTT gateway using an ESP8266. There are many TBD/TODO items but it has enough functionality to be useful. I have mosquitto running on a Pi but have not decided whether to use openHAB or node-red or something else. I am considering implementing the automation logic on the ESP8266 since it has 3 MB for file storage web server assets and free code and RAM space. But I will be working on the Moteino side for a while.

https://github.com/bbx10/nanohab

Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: TomWS on July 13, 2016, 07:42:26 AM
Thanks for the info and the link.  This looks like a good read!

One bit of advice...
Uses about 110mA @ 5V measured using a meter.
Plan on having at least 500mA power supply.  Nominal currents may be around 100mA, but surges will be much higher than this.

Tom
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: rfmesp on July 13, 2016, 04:25:41 PM
Thanks, I'm using 5V 1A wall adapter but I agree 0.5A should be sufficient. Peak power with WiFi and RFM69 transmitting will definitely much higher thatn 110mA but for short periods of time. The meter reading gives average power usage which is useful to know for devices that run 24/7.
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: radu022003 on April 13, 2017, 06:51:17 PM
Hello, I am using now a few DHT22 + Arduino Pro mini+ RFM69HW sensors and a serial gateway (Arduino pro mini + rfm69hw) everything works fine.
Now I want to make the gateway wireless, using wemos d1 mini + rfm69hw.
I used the sketch rfm69gw, i compiled it using the libraries described in github page.
Application is starting and is receiving from my sensors something. the data is not inteligible.
On my sensors I used the example from your library using the Payload structure.

I tryed to implement on the ESP8266 gateway the same structure, but data is not what I am expecting.

can you please help me to figure out where is the problem?
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: radu022003 on April 14, 2017, 11:49:30 AM
after some more reading, I found out that is a problem related to data alignment. Arduino pro mini is 8 bit and ESP8266 is 32 bit. So I declared the struct like this:

Code: [Select]
typedef struct {    
  uint16_t           nodeId; //store this nodeId
  uint16_t          light;
  uint16_t          batt;
  double         temp;   //temperature maybe?
  double         humid;
} Payload;

but, i still have problems with temperature and humidity, for these I haven't found a solution so far. I want to do this in order to avoid reflashing my sensors.

Help would be high apreciated.

Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: furieux on March 10, 2018, 02:26:21 PM
I know this is an old topic, but I came across the same problem (Node is 8-bit AVR, but Gateway is 32-bit ESP-12E).

So if someone else is still having issues with data received, this worked for me:

Code: [Select]
typedef struct __attribute__((__packed__)) {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: TomWS on March 10, 2018, 03:02:52 PM
I know this is an old topic, but I came across the same problem (Node is 8-bit AVR, but Gateway is 32-bit ESP-12E).

So if someone else is still having issues with data received, this worked for me:

typedef struct __attribute__((__packed__)) {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;
Yes, this works, but only if your ESP8266 toolchain sets the processor and uses little endian data organization since the ESP8266 can be either (little or big endian).  Fortunately, and not too surpisingly, the ESP8266 Arduino toolchain does just this and I mention this only because the 'ambidextrous' behavior of the ESP8266 could surprise you and, as a general rule, it's always best to check when exchanging binary data between two dissimilar processors.

This is also one of the reasons to use 'size' typed variables (eg uint16_t instead of unsigned int) when building data packets.

Tom
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: furieux on March 10, 2018, 04:12:16 PM
TomWS, thanks for pointing this out.

That means on AVR node instead of this:

Code: [Select]
typedef struct {
  int node_id;
  float temp;
  float hum;
  int batt;
} Payload;

I should use this:

typedef struct {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;

Or what would be the correct method?
Title: Re: nanohab -- ESP8266 RFM69 MQTT gateway
Post by: TomWS on March 10, 2018, 05:29:03 PM
TomWS, thanks for pointing this out.

That means on AVR node instead of this:

typedef struct {
  int node_id;
  float temp;
  float hum;
  int batt;
} Payload;

I should use this:

typedef struct {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;
Well, we're mixing signed-ness with size and they are entirely different.  IF you really want a signed integer to pass back and forth in a packet, you could use:
Code: [Select]
typedef struct {
  int16_t node_id;
  float temp;
  float hum;
  int16_t batt;
} Payload;
or, if you really do want unsigned values, this is fine:
Code: [Select]
typedef struct {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;
Note that, in these cases, 'float' is accepted to be a single precision IEEE floating point value (whose size is standard, unlike ints).

Finally, so that you can use a single include file to be defining the packet structures with the same file on both ends, including the packed attribute, as you had earlier, is also fine (the attribute is redundant on the AVR processor).

 
Code: [Select]
typedef struct __attribute__((__packed__)) {
  uint16_t node_id;
  float temp;
  float hum;
  uint16_t batt;
} Payload;

Tom