The temperature sensor that I selected is the BME280. It measures humidity and barometric pressure in addition to temperature. The particular version that I'm using interfaces over I2C. There are other versions that will interface with I2C or SPI at the expense of a slightly larger PCB due to the additional 2 pins required for SPI.
I decide to test the temperature sensor code using my second MKR 1300 so that I could verify that it is also working. The module that I am using is compatible with the Adafruit BME280 Arduino library so the part of the code that interfaces to the sensor is straightforward. Then I needed to format the data for transmission to the TTN interface and also write a payload decoder for the data when it is received at the TTN console.
I should note that I'm still having some difficulty getting the devices to connect to TTN reliably. Once I get connected everything works well but whenever I go through a program update cycle it takes multiple tries to reconnect. Very frustrating in the development cycle. The double reset that I thought was helping was just a 'red herring'. It just coincidentally worked a few times in a row, but it really doesn't work consistently. I've added a loop that attempts to connect for 10 times before quitting and that helps but doesn't completely solve the problem. I tried changing connection modes from OTAA (over the air activation) to ABP (activating-by-personalization) but in ABP mode I don't see any traffic on my gateway even though the joinABP function returns a value indicated that I'm connected. And I don't receive any data in the TTN console. I probably don't have something set up correctly for that mode. I have seen some references in forums that it may be the MKRWAN library that has issues. I probably have to live with it for now.
Once I get connected things work fine.
Here's a log from the serial console on startup:
Here is a screenshot of the data in the TTN console:
And a closer look at one of the decoded JSON data packets:
And TTN has an integration that will provide temporary database storage (7 days). Here is data extracted by query from the database:
[
{
"altitude": 35,
"battery": 3.1,
"bytes": "GlEQdCdqAV4BNg==",
"device_id": "mkrwan2",
"humidity": 42.12,
"pressure": 1009,
"raw": "GlEQdCdqAV4BNg==",
"temperature": 27.370000000000005,
"time": "2019-07-28T03:15:36.34884366Z"
},
{
"altitude": 35,
"battery": 3.1,
"bytes": "GlMQbSdqAV4BNg==",
"device_id": "mkrwan2",
"humidity": 42.05,
"pressure": 1009,
"raw": "GlMQbSdqAV4BNg==",
"temperature": 27.39,
"time": "2019-07-28T03:16:36.335962617Z"
},
{
"altitude": 35.3,
"battery": 3.1,
"bytes": "GlMQYSdqAWEBNg==",
"device_id": "mkrwan2",
"humidity": 41.93,
"pressure": 1009,
"raw": "GlMQYSdqAWEBNg==",
"temperature": 27.39,
"time": "2019-07-28T03:17:36.332603088Z"
}
]
The altitude data is derived from a presumed barometric pressure at sea level, so it isn't very accurate and varies quite a bit over time. I'm just going to rely on the GPS data for altitude.
I guess it's time to package everything up and hopefully I can work through some of these issues afterwards.