In most IoT projects, your sensing device is likely to be left unattended for a few months or even years. This is why power consumption is an important factor when selecting your IoT hardware platform.
In this test we wanted to know how many times a Ubidots variable can be updated using Linkit's WiFi with the 1000mAh battery it ships with.
Testing Code
This code sends an incremental value to a Ubidots variable, and the battery level to another Ubidots variable.
Keep in mind that the Linkit will only return 4 possible values for the battery level: 100%, 66%, 33% or 0%.
First, we setup some constants:
#include
#include
#include
#include
#define WIFI_AP "Abriles_LTE"
#define WIFI_PASSWORD "12345678"
#define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.
// Ubidots information
#define URL "things.ubidots.com"
#define TOKEN "6ZIxxxxxxhPWecutlxxxxxxOpjRps" // replace with your Ubidots token generated in your profile tab
#define VARIABLEID1 "5576280e76254212a7d0ece9" // create a variable in Ubidots and put its ID here (http://app.ubidots.com/ubi/datasources/)
#define VARIABLEID2 "55762817762542133c9726ba" // create a variable in Ubidots and put its ID here (http://app.ubidots.com/ubi/datasources/)
int counter = 0;
Then we setup the WiFi connection:
void setup()
{
LTask.begin();
LWiFi.begin();
Serial.begin(9600);
// keep retrying until connected to AP
Serial.println("Connecting to AP");
while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
{
delay(1000);
}
}
The main loop will just increment a counter and read the battery level, then send both values to Ubidots (using a separate request for each):
void loop()
{
save_value(String(counter++), VARIABLEID1);
save_value(String(LBattery.level()), VARIABLEID2);
}
The "save_value" function receives the Ubidots variable id and a string containing the value to be sent:
void save_value(String value, String VARIABLEID){
Serial.println("Sending value to Ubidots...");
LWiFiClient c;
while (!c.connect(URL, 80))
{
Serial.println("Retrying to connect...");
delay(100);
}
String data = "{\"value\":"+ value + "}";
String thisLength = String(data.length());
// Build HTTP POST request
c.print("POST /api/v1.6/variables/");
c.print(VARIABLEID);
c.print("/values?token=");
c.print(TOKEN);
c.println(" HTTP/1.1");
c.println("Content-Type: application/json");
c.println("Content-Length: " + thisLength);
c.print("Host: ");
c.println(URL);
c.print("\n" + data);
c.print(char(26));
// read server response
while (c){
Serial.print((char)c.read());
}
c.stop();
}
Results
This test allowed us to see the amount of HTTP Post requests sent by the Linkit while looking at its battery level. In general, we were positively impressed with the performance of the Linkit board.
Although some times the board reset itself automatically -and other times we had to manually reset it so it could continue to post data (probably due to temporary loss of Internet connection)- these are normal issues that can be solved through more stable firmware. For example, a watchdog function can be written to reset the board automatically when no Internet is detected.
The board resets made it difficult to know how many updates it sent based on the incremental counter, so we used a "Statement Widget" to know how many times the variable was updated. This can also be queried using Ubidots' Statistics API Endpoint, which allows us to query operations like "count", "sum", "min", "max", etc.:
15.000 updates is a good number for a 1000mAh battery, but remember we were also sending the battery level, so we actually sent 30.000 updates with a single charge!
How much is 30k updates?
This is a good number, depending of course on your firmware, how it manages the battery life and if it can go into sleep mode between each update.
According to our tests, a single battery charge would allow you to have an autonomous sensing device that can be left unattended for:
Comments