# LoRaWan solar gateway monitoring

In a previous post, I’ve been introduce my home made LoRaWan solar powered outdoor gateway. I’ve been investigating on the minimal hardware to make it running and reach some interesting result in my garden ;). Now it’s time to deploy the gateway on the field (basically on a roof top) and this means I’ll not be able to continue to learn what how it evolves over time.

• Battery Voltage
• Battery in & out power
• 5V powering availability
• Temperature

For this I’ve selected a simple and LoRaWan all-included Arduino platform I already detailed in a previous post: the LoRa Radio Node. Let’s detail this project now available on github.

## Hardware requirement

• 1x – LoRa Radio Node (20€)
• 1x – LifePO4 3.2V AA battery 900mAh (5€)
• 1x – INA219 Current / Voltage sensor (3-6€)
• 1x – 0,05mOhm resistor (or an extra 0.1mOhm resistor)
• 2x – 1MOhm resistor
• 1x – 0,1uF capacitor
• 1x – usb power cable to cut
• 1x – small pcb breadboard

The total cost of the solution is about 30€.

## Sensors circuits

### Battery Current & Voltage sensor

The INA219 board is able to measure 0-26V Voltage. The current is measured with a Voltage variation up to +/- 320mV over a shunt resistor. With a shunt of 100mOhm (0.1Ohm) this allows to measure current +/-3.2A.

In the solar application with a 100W / 12W panel, it means some possible pic of 8A. This is far away from what I measured previously with my panel but standard 3.2A is too small for this configuration.

The way to change this scale is to change the shunt resistor on the INA219 board (the big one with R100 printed on it). For 8A, the best would be to use a 0.04Ohm (40mOhm) resistor. The simple way to approximate this one, I found was to solder a second R100 extracted from a second board is parallel of the first one. This gives a 50mOhm resistor associated with a 6.4A measurement capability.

The dissipated power over the resistor can reach 3.2W, you should select your resistor according to this and / or select a smaller resistor like 20mOhm to limit the power over the resistor to 1.xW.

The circuit needs to be connected to I2C bus, battery circuit and ground.

This sensor board have existing drivers from Adafruit and “DeCristofaro…” This last one is the one I’ve selected and modified because of the long list of dependencies the Adafruit lib have. When developing LoRaWan solution with LoRa Radio node board, you really need to be careful with the library size because LoRaWan lib does not let you much space…

For this reason, I’ve forked and include in the main code a light version of the INA219 library with all variable fixed and no global memory variables.

As a consequence, if you change the shunt resistor you will have to recompute these constants (remove comment on calibrate function, change the values and report the result to the getData function).

### Get the status of the harvester USB connector

The status of the USB connector where the TTIG gateway is connected let you know if the gateway is under power or not. For sure measuring and reporting this information makes no sense if your messages are only relayed by that gateway… But if you have multiple gateways around, it makes sense. This will let you know if a disconnection is related to a WiFi loss or a Power loss.

The way I’ve chosen to verify this status was to measure the USB voltage over a voltage division with the circuit on the left.

A0 is connected to LoRa Radio Node A0 pin. USB ground is connected to LoRa Radio Node GND also. The Arduino code will measure the voltage on A0 and above a certain threshold power will considered ON.

For the USB connector, I’ve cut a power only USB cable so there is only 2 wires in it with easy identifiable color.

### Power consideration

This board have to measure the solar station status autonomously and its power consumption is a key point. I’ve implemented LowPower Arduino feature and obtained an acceptable sleep consumption.

With 693uA @ 3.2V the 900mAh LifePo4 battery should operate the solution for 54 days. With the transmission it should be around a month. Good to me for my experiment.

Another way could be to connect to the 5V USB supply with a DC-DC converter to 3.3V to power the system.

## Software solution

The Radio Lora Node runs an Arduino sketch. All the source code is available on Monitor LoRaWan Solar Gateway github project. The project basically have two dependencies:

• The MCCI LoRaWAN LMIC stack
• The Low-Power (by Rocket Scream…) library

For the INA219 I’ve decided to fork the library written by “DeCristofaro John…” to optimize the memory footprint.

I’ve deal with internal temperature measurement and VCC measurement to also track the temperature effect and the status of the monitoring Arduino board battery.

The source code is finally 25Kb (82% of the available flash) and the RAM is 92% used by global… so we are at the limit of what we can get.

The information are reported on every 5 minutes to TheThingsNetwork.

## Connect to a dashboard

### MyDevice Cayenne

It is really easy to connect the device to a Cayenne Dashboard. You just need to create a MyDevice Integration in TTC console and then add a cayenne LPP device into the cayenne dashboard. Unfortunately, as many time I’ve tried Cayenne I had a lot of issue to correctly design my dashboard and access all my data. Here the temperature was not displaying history as an example… So you can try it but I was looking for something new.

### TheThings.io

This platform has been developed by Marc Pous and this was a nice opportunity to test his platform. You can register a trial period for 15 days.

Then you add a new device from the “things’ panel with LoRa as a type.

Once it has been created, click on product details to get the integration callback url:

Now you can enter this url on TheThingsNetwork console as an HTTP integration. The url is like

``https://subscription.thethings.io/lora/2XXXX/ImN7ZI4dXXXXXX?idname=dev_id``

At the end, you really write dev_id, this is, in fact, in the body, the name of the field containing the device ID.

In the TTN console, in the Application dashboard, you need to add a Payload Format decoding function:

``````function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.

// Signed values
var batC = 256*bytes[6]+bytes[7];
if ( batC >= 32768 ) {
batC = batC - 65536;
}

var boardTemp = (256*bytes[2]+bytes[3]);
if ( boardTemp >= 32768 ) {
boardTemp = boardTemp - 65536;
}

var decoded = {
boardTemperature:boardTemp/10.0,
batteryCurrent:batC/100.0,
batteryVoltage:(256*bytes[10]+bytes[11])/100.0,
boardVoltage:(256*bytes[14]+bytes[15])/100.0,
externalPowerState:bytes[18],
batteryPower:(256*bytes[21]+bytes[22])/100.0
};

return decoded;
}``````

Thanks to this, you will be able to access the metrics in TheThings.io. For this, modify the lora_parser function automatically created by the platform

The function will contains:

``````function main(params, callback){
var result = [
{
"key": "boardTemperature",
},
{
"key": "batteryCurrent",
},
{
"key": "batteryVoltage",
},
{
"key": "boardVoltage",
},
{
"key": "externalPowerState",
},
{
"key": "batteryPower",
},
]
callback(null, result);
}``````

Now you can see the values in the device details or you can create your dashboard with the information you want to see.

Once that done, you can create your dashboard with these values: here is what I’ve got:

## 4 thoughts on “LoRaWan solar gateway monitoring”

• If you are in the USA, US915 could not have it due to different regulation. use SF_10 instead.

This site uses Akismet to reduce spam. Learn how your comment data is processed.