hello i try to push data to cloud using esp8266 but esp8266 doesnt connect to thinger… plis help
here is my code:
#include<ESP8266WiFi.h>
#include <ThingerESP8266.h>
#define USERNAME "XXX"
#define DEVICE_ID "XXX"
#define DEVICE_CREDENTIAL "XXX"
#define TRIGGER_PIN 14 // D5
#define ECHO_PIN 12 //D6
//defining SSID and password for the router
#define SSID "HUAWEI P10 Plus"
#define SSID_PASSWORD "miofab9982"
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
#define TRIGGER 13
#define ECHO 15
// NodeMCU Pin D1 > TRIGGER | Pin D2 > ECHO
unsigned long startTime;
unsigned long endTime;
unsigned long dura;
unsigned long second;
byte timerRunning;
void setup() {
Serial.begin (9600);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BUILTIN_LED, OUTPUT);
thing.add_wifi(SSID, SSID_PASSWORD);
thing["SONIC"] >> [] (pson& out){
long duration, distance;
digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration/2) / 29.1;
};
}
void loop() {
thing.handle();
long duration, distance;
digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration/2) / 29.1;
if (distance <5 && timerRunning == 0 ) //if detect
{
startTime = millis();
timerRunning = 1;
}
else if(distance >5 && timerRunning == 1 ) //no detect
{
endTime = millis();
timerRunning = 2;
dura = endTime - startTime;
second = dura/1000;
}
else if(second >5 && timerRunning == 2 )
{
Serial.print ("park time in seconds: ");
Serial.println (second);
timerRunning = 0;
}
else if(second <5 && timerRunning == 2 )
{
timerRunning = 0;
}
thing["SONIC"] >> [] (pson& out){
out = second;
};
delay(100);
}