How to push data from a device?

Helllo @Handy_ID,

you can try with something like:

if(millis()%(1000*60*15)==0)thing.stream("TempHum");

Hi, nice code. I tryed to use it as sample, but it disconnects after 2 min, and not connect again? do you have idea why? thanks

Hi, write at the top of your sketch the following:

#define _DEBUG_

It will give info about what is going on with the cloud process, paste the serial console report to see how can we help you.

Have you connected the ESP8266 RST pin to D0 so that it can wake up?

Hi @shean,

D0 on '66 contains the boot mode selection. The right wiring to wkup using the watchdog is GPIO16 which contains the XPD_DCDC. With this wiring you can implement ESP.deepsleep function with really low power consumption, which is quite useful while working with batteries BTW.

Hi, thanks for the reply, i started from your code, and from the “climastick” example, i managed to make it stay connected and write to bucket every x time i want… it works perfectly… BUT… i’m trying to adapt for my application and it cannot connect att all!! please can you have a look? posting the code that works, and after the one that doesn’t work…

#define DEBUG // Grazie a questi finalmente si e’ connesso, dopo infiniti tentativi
#define DISABLE_TLS //
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h> // req’d by thinger

// THINGER ID LOGIN CREDENTIALS
#define USERNAME “sistralsrl”
#define DEVICE_ID “WemosIFRprototipo”
#define DEVICE_CREDENTIAL “ifr1234”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// LAN WIFI CREDENTIALS
#define SSID “Rigert”
#define SSID_PASSWORD “albinoniE45”

// SET A TIME PERIOD TO UPDATE TEMP AND HUMID READINGS
//#define SLEEP_MS 120000 // 60,000 milliseconds FOR DEEPSLEEP MODE

// DHT11 START
#include “DHT.h”
float temperature;
float humidity;
#define DHTPIN D2 // ESP8266 pin number for DHT11 data pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
// DHT11 END

int timer = 0;

// SETUP START
void setup() {

//// TEMP HUMIDITY DEVICE
dht.begin();
//// END TEMP DEVICE

//// WIFI STUFF
Serial.begin(115200);
delay(100);
Serial.println(“Booting”);

//// WIFI STUFF END

//// THINGER START
thing.add_wifi(SSID, SSID_PASSWORD);

thing[“WemosIFR”] >> [](pson& out){
out[“temperature”] = 10 ;
out[“humidity”] = dht.readHumidity();
};
thing[“in_out”] = [](pson& in, pson& out){
out[“sum”] = (int)in[“value1”] + (int)in[“value2”];
out[“mult”] = (int)in[“value1”] * (int)in[“value2”];
out[“mult”] = (int)in[“temperature”] * (int)in[“value2”];
out[“mult”] = (int)out[“millis”] * 2;
};

  thing["temperature"] >> outputValue(millis());

//// THINGER END

}
//// SETUP END

//// TEMP HUMIDITY SUBROUTINE (not req’d except for serial print)
void TempHum(){
humidity = dht.readHumidity();
temperature = dht.readTemperature();
// Check if any reads failed and exit.
if (isnan(humidity) || isnan(temperature)) {
Serial.println(“Failed to read from DHT sensor!”);
return;
}
Serial.print(“Humidity: “); //nome della colonna
Serial.print(humidity);
Serial.print(” %\t”);
Serial.print("Temperature: “); ////nome della colonna
Serial.print(temperature);
Serial.println(” *C ");
}
//// END TEMP HUMIDITY SUBROUTINE

void loop() {
thing.handle();
if(millis()>timer+(600001)){ //call each 1 minutes (THIS MADE ME CONNECT IT STABLE)
//call thinger.io endpoint function and attacht the pson
thing.write_bucket(“BucketIFR”, “WemosIFR”); //ID Bucket , thing
//actualize time counter
timer = millis();
}
//ESP.deepSleep(SLEEP_MS
1000, WAKE_RF_DEFAULT);

//END OF THE CODE THAT WORKD

This is the adaption of my code, pretty similar but it cannot connect!!! :pensive:

#define DEBUG // Grazie a questi finalmente si e’ connesso, dopo infiniti tentativi
#define DISABLE_TLS
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h> // req’d by thinger
#include <OneWire.h> // Libreria per l’uso del protocollo unico filo
#include <DallasTemperature.h> // Libreria per la lettura della temperatura
#include <HX711.h> // Libreria per la lettura della scheda AD HX711 per ponti estensimetrici

// THINGER ID LOGIN CREDENTIALS
#define USERNAME “sistralsrl”
#define DEVICE_ID “WemosIFRprototipo”
#define DEVICE_CREDENTIAL “ifr1234”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// LAN WIFI CREDENTIALS

#define SSID “Rigert”
#define SSID_PASSWORD “albinoniE45”

// SET A TIME PERIOD TO UPDATE TEMP AND HUMID READINGS
//#define SLEEP_MS 120000 // 60,000 milliseconds FOR DEEPSLEEP MODE

#define wire D3 // Unico filo - D3 = GPIO0
#define ledPin D4 // Led scheda - D4 = GPIO2

#define GND1 D8 // Primo HX711 (Sezione 1) - GND - D8 = GPIO15
#define sezione1_SCK_PIN D7 // Primo HX711 (Sezione 1) - Clock - D7 = GPIO13
#define sezione1_DOUT_PIN D6 // Primo HX711 (Sezione 1) - Data - D6 = GPIO12
#define alim1 D5 // Primo HX711 (Sezione 1) - Alim - D5 = GPIO14
//const int sezione2_SCK_PIN = 4; // Secondo HX711 (Sezione 2) - Clock - D2 = GPIO4
//const int sezione2_DOUT_PIN = 5; // Secondo HX711 (Sezione 2) - Data - D1 = GPIO5

float temp = 0; // inizializza valore temperatura
int hx1ass = 0; // valore iniziale di 0 del primo HX711 collegato
int hx1zero = 0; // costante di 0 del Primo HX711 collegato
int hx1sens = 1; // corrisponde alla coeff di conversione digit/me/kN del primo HX711 (taratura con calibratore Pavone Sistemi)
int carico1 = 0; // inizializzazione di carico1
int soglia1 = 500; // definizione soglia1 da confrontare con carico1 dell’hx1

//int hx2ass = 0; // valore iniziale di 0 del secondo HX711 collegato
//int hx2zero = 0; // costante di 0 del Secondo HX711 collegato
//int hx2sens = 1; // corrisponde alla coeff di conversione digit/me/kN del secondo HX711 (taratura con calibratore Pavone Sistemi)

float temperature;
float humidity;

int timer = 0; // timer per lettura dati temporizzata
int freq = 20; // frequenza di lettura e trasmissione dati (in secondi)

OneWire oneWire(wire); // Sensore Temperatura DS18B20 - D3=GPIO0
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature

HX711 sezione1(sezione1_DOUT_PIN, sezione1_SCK_PIN); // We define the first scale (Sezione 1)
//HX711 sezione2(sezione2_DOUT_PIN, sezione2_SCK_PIN); // We define the second scale (Sezione 2)

// SETUP START
void setup() {
//pinMode(ledPin, OUTPUT); // collegato al led sulla scheda WeMos D1R2
//pinMode(GND1, OUTPUT); // per creare un GND
//pinMode(alim1, OUTPUT); // per creare una Alim +3.3V
//digitalWrite(GND1, LOW); // configura un GND
//digitalWrite(alim1, HIGH); // configura una Alim +3.3V

sensors.begin(); // per la lettura della temperatura
// sezione1.set_scale(221); // <- coef di calibrazione tarato per ottenere mV/V x 10000 sui HX711
// sezione2.set_scale(221); // <- coef di calibrazione tarato per ottenere mV/V x 10000 sui HX711

//// WIFI STUFF
Serial.begin(115200);
delay(100);
Serial.println(“Booting”);
//// WIFI STUFF END

//// THINGER START
thing.add_wifi(SSID, SSID_PASSWORD);

thing[“LetturaDati”] >> [](pson& out){
out[“temperature”] = sensors.getTempCByIndex(0);
out[“Hx711”] = sezione1.read_average(20);
};

thing[“in_out”] = [](pson& in, pson& out){
out[“sum”] = (int)in[“value1”] + (int)in[“value2”];
out[“mult”] = (int)in[“value1”] * (int)in[“value2”];
out[“mult”] = (int)in[“temperature”] * (int)in[“value2”];
out[“mult”] = (int)out[“millis”] * 2;
};

  thing["temperature"] >> outputValue(millis());

//// THINGER END
}
//// SETUP END

void loop() {
// if (WiFi.status() != 6) digitalWrite(ledPin, LOW); // se wifi collegato allora led scheda acceso (invertito)
// else digitalWrite(ledPin, HIGH); // nel caso contrario: led scheda spento (invertito)
//}
thing.handle();
if (millis() > timer + (freq * 1000)) { //call each “freq” minutes
sensors.requestTemperatures();
thing.write_bucket(“BucketIFR”, “LetturaDati”); //call thinger.io endpoint function and attacht the pson (ID Bucket, thing)
timer = millis(); //actualize time counter
}
//ESP.deepSleep(SLEEP_MS*1000, WAKE_RF_DEFAULT);
}

Hi @sistralsrl, two things:

1st When publish your sketchs, please post the code in the appropriate way, the forum has a tool to publish the code, it is useful to read the code in a more comfortable way, help us to help you.

2nd Please post the serial debug behaviour (as I explicit asked in my previous reply), it may save us a lot of time, instead of wasting reading and understanding all the details to find what it is wrong in your code, make the machine work for you and us (showing the issue), not us to work for them (it is a waste of time for something that could be diagnosticated in seconds), and tell us any behaviour you may see, we have experience but we cannot see across your eyes, any particular detail may help us to detect what is going on with your particular case.

I’m still waiting to help you solve the issue.

Hi, thank you and sorry for my elementary mistakes! you can find attached the sketch and as you can see on the line, just adding the inclusion of a library, it does not work, attaching also the serial monitor:

Thanks

Preformatted text

#define DEBUG /
#define DISABLE_TLS
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>

#include “DHT.h”
#include “HX711.h” //just including this, it doesn’t connect!! without this yes!!
//even this way is not connecting: <HX711.h>

#define USERNAME “sistralsrl”
#define DEVICE_ID “devid”
#define DEVICE_CREDENTIAL “pass”
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

#define SSID “Rigert”
#define SSID_PASSWORD “pass”

int timer = 0;
//int freq = 20;

#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

//#define sezione1_DOUT_PIN D6
//#define sezione1_SCK_PIN D7
//HX711 sezione1(sezione1_DOUT_PIN, sezione1_SCK_PIN);

void setup() {
Serial.begin(9600);
delay(100);
Serial.println(“Booting”);

// Setup WiFi
thing.add_wifi(SSID, SSID_PASSWORD);
// Define the ‘thing’ with a name and data direction
thing[“dht11”] >> (pson& out){
// Add the values and the corresponding code
out[“humidity”] = dht.readHumidity();
out[“celsius”] = dht.readTemperature();
//out[“Hx711”] = sezione1.read();

};
}

void loop() {
thing.handle();
if(millis()>timer+(60000*1)) { //call each “freq” minutes
thing.write_bucket(“BucketIFR”, “dht11”); //call thinger.io endpoint function and attacht the pson (ID Bucket, thing)
timer = millis(); //actualize time counter
}
}

Not working sketch

Working Sketch

I saw you opened a post with the issue, I will answer overthere.