Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Deploy a soil moisture and temperature sensor for commercial greenhouses or private garden monitoring and treatment.
// This example is to get the last value of variable from the Ubidots API
// This example is to save multiple variables to the Ubidots API with TCP method
/****************************************
* Include Libraries
****************************************/
#include "Ubidots.h"
#include <SHT1x.h>
#include <application.h>
/****************************************
* Define Constants
****************************************/
#ifndef TOKEN
#define TOKEN "Put_your_Ubidots" // Put here your Ubidots TOKEN
#endif
#ifndef DATAPIN
#define DATAPIN D0
#endif
#ifndef CLCKPIN
#define CLCKPIN D1
#endif
#ifndef LED
#define LED D7
#endif
Ubidots ubidots(TOKEN);
/****************************************
* Auxiliar Functions
****************************************/
SHT1x sht10(DATAPIN, CLCKPIN);
/****************************************
* Main Functions
****************************************/
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
//ubidots.setDebug(true); //Uncomment this line for printing debug messages
}
void loop() {
float humidity = sht10.readHumidity();
float temperature = sht10.readTemperatureC();
ubidots.add("soil-moisture", humidity);
ubidots.add("temperature", temperature);
ubidots.setMethod(TYPE_TCP); //Set to TCP the way to send data
if(ubidots.sendAll()){
// Do something if values were sent properly
Serial.println("Values sent by the device");
digitalWrite(LED, HIGH);
}
delay(5000);
digitalWrite(LED, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment