Skip to content

Instantly share code, notes, and snippets.

@mariacarlinahernandez
Last active November 1, 2019 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariacarlinahernandez/824ab7af4fb22c0bfce6df382e272b26 to your computer and use it in GitHub Desktop.
Save mariacarlinahernandez/824ab7af4fb22c0bfce6df382e272b26 to your computer and use it in GitHub Desktop.
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