First of all, apologies I am still a rookie with the Arduino IDE programming language and TTN. Nonetheless, I have managed to successfully install and run an OTTA activation and “Hello World!” application on my adafruit feather m0 over ttn.
I have now purchased a DHT11 sensor and added it to my breadboard/node but haven’t figured out how to go about setting it up to now send temp and humidity data in the payload instead of the “hello world” message. Is it as simple as using my existing code, including the dht.h file, mapping the pins, and then changing the payload?? Or would I use a completely different sketch than the original Hello World application?
I’m very confused and haven;t been able to find anything using search. Can anyone point me in the right direction or help articulate the steps I need to undertake?
Because you are new Arduino I would suggest to get the DHT11 sensor working in a seperate sketch. You can use the Adafruit library as a starting point.
Then you would need to combine the hello world sketch and the DHT11 sketch into one sketch. After that you need to change the payload to send the temperature + humidity values. Here a good page explaining the payload format:
As another option, I use “typedef struct” to define a payload array and specify the type of characters each component of the payload should be. See example below for DHT11 device that sends longitude, latitude, temperature & humidity in one payload.
With that you can create a payload variable of type PayloadTX.
PayloadTX myData;
And store your values as myData.temperature = DHT.temperature
and myData.humidity = DHT.humidity.
This may not have obvious benefits when storing single byte data but when you have to store integers or floats and need to ensure the higher and lower bytes are not mixed up, this eliminates the need to do that manually in code.
I agree with @Lennyz1988 that you should probably get a grasp of getting the DHT sensor to work before trying to subsitute it in but it shouldn’t be a long process to get from one to the other. Also as @aizukanne getting your payload in a good format is also going to be something that needs to be done, and something that if it’s formatted well will save you valuable space in your transmission payload.
The one other obvious thing that neither seemed to mention but is probably no less important is to make sure you comment out or remove the basic ‘Hello World’ variable that is sitting in the script that you are using and it’s corresponding value and the other values that pertain to it in the send or do_send(if you’re using LMIC) part of your code.
you need to know the byte order of your device when decoding, some processors will use MSB and others LSB order resulting in different decoder functions.
for some processors the compilers will align the structure members at word/double word boundaries wasting space and (as a result) airtime.
Thanks @kersing, fortunately we have been running on same bespoke board design. Now that you have mentioned this, I will have it in mind when porting to a different processor.