For a few days I am working with Thinger i’ve got working the setup with Thinger sending data through sliders reciving it with ESP12 module sending it to Arduino through Serial comunication. Than arduino sends data that it gets back all the way to Thinger where i see the response.
The part whitch posts the data back to Thinger is working perfectly, no errors.
But i am not shure why at holding slider in Thinger i got garbage values to Arduino and the same number is shown on Back Info posted to Thinger.
I ve used these kind of comand --thing[“logging”] << inputValue(sdLogging);
and it got the right value when clicked to set slider but with garbage when sliding slider.
When switching to this kind of comand–
thing[“hysteresis”] << (pson& in){ hysteresis = in;};
I can send values through API window, on the other hand slider recognized input but it refuses to set value - jumps back to 0.
Cant find the bug.
//Code for ESP module
poslji= send
prejmi = recive
#include “SPI.h”
#include “ESP8266WiFi.h”
#include “ThingerWifi.h”
#include “DHT.h”
define DHTTIP DHT22
define DHTPIN 2
DHT dht(DHTPIN, DHTTIP);
ThingerWifi thing(“", "", "*****”);
int vred;
int UPindex;
String Str;
String Sd;
String Ca;
int casZl=0;
int SvZv=1;
int SvZj=2;
int ventl=3;
int Minut;
int SvetlostZvecer;
int SvetlostZjutraj;
int i=1;
double temp;
unsigned long lastCheck = 0;
unsigned long ZC = 0;
int T = 1000;
int HomeVaria [20];
int UpVaria [20];
void setup() {
Serial.begin(9600);
pinMode(DHTPIN,INPUT);
thing.add_wifi(“*****”, “*******”);thing[“DHT”] >> (pson& out){
out[“Temperatura”] = dht.readTemperature();
out[“Vlaga”] = dht.readHumidity();
};
thing[“Back_Info”] >> (pson& out){
out[“Minut”] = UpVaria[casZl];
out[“SvetlostZvecer”] = UpVaria[SvZv];
out[“SvetlostZjutraj”] = UpVaria[SvZj];
};
thing[“Minut”] << (pson& in){Minut=in;};
thing[“SvetlostZvecer”] << (pson& in){SvetlostZvecer=in;};
thing[“SvetlostZjutraj”] << (pson& in){SvetlostZjutraj=in;};}
void loop()
{
if(millis()-ZC>T)
{
ZC=millis();
thing.handle();
poslji(0,Minut);
poslji(1,SvetlostZvecer);
poslji(2,SvetlostZjutraj);
prejmi();}
if((millis()-lastCheck>=60601000)||i==1)
{
i=2;
lastCheck = millis();
if(dht.readTemperature()>24)
{
thing.call_endpoint(“Temp_23_plus”);
}
}
}
void poslji(int index, int spr)
{
int sp;
if((spr!= HomeVaria[index])&&(0<spr<256))
{
HomeVaria[index]= spr;
sp=0;
if(index<10)
{
Serial.print(“0”+String(index) + String(spr));
}
else
{
Serial.print(String(index) + String(spr));
}
}
}
void prejmi()
{
if(Serial.available())
{
Str = Serial.readString();
Ca = Str.substring(0,2);
Sd = Str.substring(2,Str.length());
vred = Sd.toInt();
UPindex = Ca.toInt();
UpVaria[UPindex]=vred;
}
}
//Code for Arduino
#include “LiquidCrystal_I2C.h”
LiquidCrystal_I2C lcd(0x27,16,2);
#include “Wire.h”
int casZl=0;
int SvZv=1;
int SvZj=2;
int ventl=3;
int vred;
int po = 1;
int HOMEindex;
String Str;
String Sd;
String Ca;
int HomeVaria [20];
int UpVaria [20];
unsigned long ZC = 0;
int T = 1000;
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.init();
lcd.backlight();
}
void loop()
{
if(millis()-ZC>T)
{
ZC=millis();
prejmi();
poslji(0,HomeVaria[casZl]);
poslji(1,HomeVaria[SvZv]);
poslji(2,HomeVaria[SvZj]);
po++;
LCD();
}
}
void poslji(int index, int spr)
{
if((spr!= UpVaria[index])||po<8)
{
UpVaria[index]= spr;
if(index<10)
{
Serial.print(“0”+String(index) + String(spr));
}
else
{
Serial.print(String(index) + String(spr));
}
}
}
void prejmi()
{
if(Serial.available())
{
Str = Serial.readString();
Ca = Str.substring(0,2);
Sd = Str.substring(2,Str.length());
vred = Sd.toInt();
HOMEindex = Ca.toInt();
HomeVaria[HOMEindex]=vred;
}
}
void LCD()
{
lcd.setCursor(0,0);
lcd.print(“Cas:”+String(HomeVaria[casZl]));
lcd.print(" SvZv:“+String(HomeVaria[SvZv]));
lcd.setCursor(0,1);
lcd.print(” SvZj:“+String(HomeVaria[SvZj]));
lcd.print(” Test:");
}
Thanks in anvance, Matej.