Cit. Gabriele F. ;-)
I like to experiment with new platforms with our citrus lemon device, especially with 3rd party cloud integration, especially when they are FREE.
(The code can also be used with other ESP8266 by changing the variables in datatosend.cpp and.h files and changing the libraries to be used in the.ino file)
In this case I wanted to try the cloud platform of my friend Fabio Rosa CEO of Tago.IO, a wonderful person. I also got to know the whole TAGO team....it's really special.
At the moment Tago.io, in my opinion, is one of the best Cloud platforms available for IoT, IIoT devices and more. Complete and easy to use cloud but with great features (explore it).
Tago has three products, TagoIO, TagoRUN and TagoCore, all aimed primarily at: Agriculture, Construction, City, Energy, Industry, Transportation and Supply Chain.
Strengths, excellent management, data retention and security and above all many tools for customizing the GUI and much more. (explore it)
Using Tago.io you can also create great looking apps with very few resources.
I invite everyone to try the Tago.io platform
Anyway, if you find it difficult to use Agrumino with this Cloud, write me in the comments, I'll be happy to help you, but you're all too good. ;-)
Step By stepCreate new tago.io accountand after click Sign up
We are ready !!!!!
Now Sign in Tago platform.
in my account I have enabled two-factor authenticator, security first!!!!!
Now click Custom HTTPS
Select your device name and click "Create my Device" in bottom right
now you have this screen
copy your token you need to add this in the Arduino sketch, in datatosend.cpp
From the Arduino library manager we download the latest Lifely Library (in this moment 1.5.2) and load the example present in the library, exaclyt in the Cloud folder. We choose Tago.IO
Another way is to download all the files from the repository included in this project and then upload it to your IDE.
The repository have three files, LIFELY_Agrumino_Lemon_with_TAGO_IO.ino, datatosend.cpp and datatosend.h.
Connect your Lifely Agrumino Lemon to the PC with the micro USB cable and start modifying some variables in the code.
You need to change only a few variables inside the datatosend.cpp file
The first change your device Tago Token. Paste or write your token copied in the previous step paste in the variable " apiTagoDeviceToken".
Next edit networkName and networkPassword with your network data.
datatosend.cpp
/*
Created by gabriele.foddis@lifely.cc on December 2022.
for LIFELY_Agrumino_Lemon_with_TAGO_IO.ino
Latest changes and updates 03/2023 by:
Gabriele Foddis gabriele.foddis@lifely.cc
for a better experience use Visual Studio Code and Platformio
*/
#include <Arduino.h>
//#define ARDUINOJSON_USE_LONG_LONG 0 //set 1 if necessary
//#define ARDUINOJSON_USE_DOUBLE 0 //set 1 if necessary
#include <ArduinoJson.h>
#include "C:\Users\gabri\Documents\Arduino\Lifely_Agrumino_Lemon_Tago_IO\datatosend.h" ///add your path for datasotosend.h
unsigned int SLEEP_TIME_MIN = 5;//Time in minute, max value is 60 minutes min value is 1
const char* networkName = "PlumCake"; // your SSID network
const char* networkPassword = "ImVeryHappy"; // SSID password
const char* serverName = "http://api.tago.io/data"; //don't edit this
String apiTagoDeviceToken = "cd8ccc84-1b8a-4fe1-bb85-0terf14c2cc1"; //Your TAGO.IO Token
long int alwaysOnTime = 5000; ///Set this time in millisecond for your "always on delay" (default 5000 (5 seconds)) min value is 1
boolean isBatteryCharging;
boolean alwaysON = false; // Set true if you need real time monitor data, default is false.
double temperature;
double lux;
double batteryVoltage;
unsigned int soilMoisture;
unsigned int batteryLevel;
String outputData;
void dataToSend(){
StaticJsonDocument<1024> data;
JsonObject data_T = data.createNestedObject();
data_T["variable"] = "Temperature";
data_T["value"] = temperature;
data_T["group"] = "1";
data_T["unit"] = "°C";
JsonObject data_SM = data.createNestedObject();
data_SM["variable"] = "SoilMoisture";
data_SM["value"] = soilMoisture;
data_SM["group"] = "1";
data_SM["unit"] = "%";
JsonObject data_L = data.createNestedObject();
data_L["variable"] = "Lux";
data_L["value"] = lux;
data_L["group"] = "1";
data_L["unit"] = "Lux";
JsonObject data_BL = data.createNestedObject();
data_BL["variable"] = "BatteryLevel";
data_BL["value"] = batteryLevel;
data_BL["group"] = "1";
data_BL["unit"] = "%";
JsonObject data_BV = data.createNestedObject();
data_BV["variable"] = "BatteryVoltage";
data_BV["value"] = batteryVoltage;
data_BV["group"] = "1";
data_BV["unit"] = "V";
JsonObject data_BC = data.createNestedObject();
data_BC["variable"] = "BatteryCharging";
data_BC["value"] = isBatteryCharging;
data_BC["group"] = "1";
data_BC["unit"] = "T/F";
delay(300);
serializeJsonPretty(data, outputData);
//Serial.print("json is: " + outputData); ///print to debug json data
}
datatosend.h
/*
Created by gabriele.foddis@lifely.cc on December 2022.
for LIFELY_Agrumino_Lemon_with_TAGO_IO.ino
Latest changes and updates 03/2023 by:
Gabriele Foddis gabriele.foddis@lifely.cc
for a better experience use Visual Studio Code and Platformio
*/
#include <Arduino.h>
//#define ARDUINOJSON_USE_LONG_LONG 0 //set 1 if necessary
//#define ARDUINOJSON_USE_DOUBLE 0 //set 1 if necessary
#include <ArduinoJson.h>
#include "C:\Users\gabri\Documents\Arduino\Lifely_Agrumino_Lemon_Tago_IO\datatosend.h" ///add your path for datasotosend.h
unsigned int SLEEP_TIME_MIN = 5;//Time in minute, max value is 60 minutes min value is 1
const char* networkName = "PlumCake"; // your SSID network
const char* networkPassword = "ImVeryHappy"; // SSID password
const char* serverName = "http://api.tago.io/data"; //don't edit this
String apiTagoDeviceToken = "cd8ccc84-1b8a-4fe1-bb85-0terf14c2cc1"; //Your TAGO.IO Token
long int alwaysOnTime = 5000; ///Set this time in millisecond for your "always on delay" (default 5000 (5 seconds)) min value is 1
boolean isBatteryCharging;
boolean alwaysON = false; // Set true if you need real time monitor data, default is false.
double temperature;
double lux;
double batteryVoltage;
unsigned int soilMoisture;
unsigned int batteryLevel;
String outputData;
void dataToSend(){
StaticJsonDocument<1024> data;
JsonObject data_T = data.createNestedObject();
data_T["variable"] = "Temperature";
data_T["value"] = temperature;
data_T["group"] = "1";
data_T["unit"] = "°C";
JsonObject data_SM = data.createNestedObject();
data_SM["variable"] = "SoilMoisture";
data_SM["value"] = soilMoisture;
data_SM["group"] = "1";
data_SM["unit"] = "%";
JsonObject data_L = data.createNestedObject();
data_L["variable"] = "Lux";
data_L["value"] = lux;
data_L["group"] = "1";
data_L["unit"] = "Lux";
JsonObject data_BL = data.createNestedObject();
data_BL["variable"] = "BatteryLevel";
data_BL["value"] = batteryLevel;
data_BL["group"] = "1";
data_BL["unit"] = "%";
JsonObject data_BV = data.createNestedObject();
data_BV["variable"] = "BatteryVoltage";
data_BV["value"] = batteryVoltage;
data_BV["group"] = "1";
data_BV["unit"] = "V";
JsonObject data_BC = data.createNestedObject();
data_BC["variable"] = "BatteryCharging";
data_BC["value"] = isBatteryCharging;
data_BC["group"] = "1";
data_BC["unit"] = "T/F";
delay(300);
serializeJsonPretty(data, outputData);
//Serial.print("json is: " + outputData); ///print to debug json data
}
LIFELY_Agrumino_Lemon_with_TAGO_IO.ino
/*LifelyAgruminoLemonForTAGO_IO-
Created by Gabriele Foddis on 12/2022, last update 03/2023
gabriele.foddis@lifely.cc
With this Sketch you can send data from your Fantastic Lifely Agrumino Lemon Device in the Tago.IO Cloud Platform
For better experience use this with Visual Studio Code and Platformio. You can also use it with Arduino Ide.
Important, edit data in datatosend.ccp. You can configure the sending timing and you can use it in always-on mode as well
Build your amazing dashboard in the Tago.IO Cloud
This sketch need a internet connection and an account from www.tago.io
Find Lifely Agrumino Lemon (REV4 AND REV5) in www.lifely.cc */
#include <Arduino.h>
//#define ARDUINOJSON_USE_LONG_LONG 0 //set 1 if necessary
//#define ARDUINOJSON_USE_DOUBLE 0 //set 1 if necessary
#include <ArduinoJson.h>
#include "datatosend.h" /// before burn and upload edit datatosend.cpp data
#include <Agrumino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#define SERIAL_BAUD 115200
#define MIN_TO_MS (1000000 * 60)
#define HTTPCLIENT_1_1_COMPATIBLE 1
Agrumino agrumino;
void readDataFromDevice(){
isBatteryCharging = agrumino.isBatteryCharging();
temperature = agrumino.readTempC();
soilMoisture = agrumino.readSoil();
lux = agrumino.readLux();
batteryVoltage = agrumino.readBatteryVoltage();
batteryLevel = agrumino.readBatteryLevel();
delay(200);
}
void blinkAndSleep() {
agrumino.turnLedOn();
delay(200);
agrumino.turnLedOff();
if(alwaysON == false && SLEEP_TIME_MIN > 1 ){
Serial.println("I sleep for: "+String(SLEEP_TIME_MIN) + " minutes...");
ESP.deepSleep(MIN_TO_MS * SLEEP_TIME_MIN);
}
if(alwaysON == false && SLEEP_TIME_MIN == 1){
Serial.println("I sleep for: "+String(SLEEP_TIME_MIN) + " minute...");
ESP.deepSleep(MIN_TO_MS * SLEEP_TIME_MIN);
}
else if (alwaysON == true)
Serial.println("I read and send data every : "+ String(alwaysOnTime) + "milliseconds");
delay(alwaysOnTime);
}
void setup() {
Serial.begin(SERIAL_BAUD);
agrumino.setup();
agrumino.turnBoardOn();
WiFi.begin(networkName, networkPassword);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi network ("+String(networkName)+") with IP Address: ");
Serial.print(WiFi.localIP());
agrumino.turnLedOn();
delay(200);
agrumino.turnLedOff();
}
void loop() {
readDataFromDevice();
dataToSend();
WiFiClient tagoClient;
delay(100);
HTTPClient httpTagoClient;
delay(100);
httpTagoClient.begin(tagoClient, serverName);
httpTagoClient.addHeader("Content-Type", "application/json; charset=UTF-8");
httpTagoClient.addHeader("Device-Token", apiTagoDeviceToken);
int httpCode = httpTagoClient.POST(outputData);
delay(200);
//Serial.println("Data Sent is: " + String(output)); //print JsonData
if (httpCode > 0) {
Serial.printf("[HTTP] POST... code: %d\n", httpCode);
if (httpCode == HTTP_CODE_OK) {
const String& payload = httpTagoClient.getString();
Serial.println("I Received this payload:\n<<");
Serial.println(payload);
Serial.println(">>");
}
} else {
Serial.printf("[HTTP] POST... failed, error: %s\n", httpTagoClient.errorToString(httpCode).c_str());
}
Serial.println("HTTP Response code: ");
Serial.println(httpCode);
delay(100);
httpTagoClient.end();
tagoClient.stopAll();
Serial.println(ESP.getFreeHeap());
blinkAndSleep();
}
In the firmware you can activate the always on function, or take advantage of the deepSleep function for energy saving, the choice is yours.
Only for this test uncomment the line number 74, we see the whole json generated according to Tago platform specifications (Important to debug)
Now compile and upload the firmware, after open serial monitor.If http response is code:202 data has been transmitted
If http response is code:202 the data has been transmitted.
Let's check immediately, in the Tago Home click Buckets
after select bucket created automatically when creating the device.
If the data is present, all works fine Happy!!!!!
Last step is to create a dashboard.To do it is very simple, I just show you a widget, then have fun, do it yourself.
Click "+"Write dashboard name, select Normal and after select Create my Dashboard
Add first widget
select widget type (for this example select Cylinder)
Edit Title (for example Battery) and select your device and variable to use (in this step I use batterylevel variable (all widget are 99, 9% customizable)
I changed the color, now click Create
This is your first widget
This is my dashboard!!!!
If you want if possible to create your custom App, but you need to use Tago.io Run. Find Icon Run in home.
My custom app is this https://623d93da0d1feb0011bb9163.tago.runI think I explained everything to you.
Now your fantasy will have to do the best.
If you find difficulties, write in the comments, I will reply asap.
If you liked it and would like to see other projects remember to like this project.
Comments
Please log in or sign up to comment.