Got it working as i wanted. i,m not the best with parsing, i belive there probably is a more efficient way to do it. But for now it works and it operates stable and i’m very happy
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include “Wire.h”
#include “OLedI2C.h”
OLedI2C LCD;
const char* ssid = “WIFI”;
const char* password = “PWD”;
unsigned long previousMillis = 0;
long getTime = 5000;
float tempIn = 0;
float tempOut = 0;
void setup() {
WiFi.mode(WIFI_STA);
Serial.begin(115200);
Wire.begin(0, 2);
LCD.init();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= getTime) {
get_tempIn();
get_tempOut();
previousMillis = currentMillis;
}
LCD.sendString(“Ute :”,0,0);
LCD.sendFloat(tempOut,6,2,9,0);
LCD.sendString(“Inne :”,0,1);
LCD.sendFloat(tempIn,5,2,10,1);
}
void get_tempIn() {
String payload;
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://api.thinger.io/v1/users/[USER]/buckets/[BUCKET]/data?items=1&max_ts=0&sort=desc&authorization=[TOKEN]"); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
payload = http.getString(); //Get the request response payload
/* Serial.print("Recived String: ");
Serial.println(payload); //Print the response payload
Serial.println("");
*/
}
http.end(); //Close connection
}
// [{“ts”:1543332383431.0,“val”:24.25}]
int firstIndex = payload.indexOf(’:’);
int secondIndex = payload.indexOf(’,’, firstIndex +1);
int thirdIndex = payload.indexOf(’:’, secondIndex +1);
int fourthIndex = payload.indexOf(’}’, thirdIndex +1);
//String firstValue = payload.substring(0, firstIndex);
//String secondValue = payload.substring(firstIndex +1, secondIndex);
//String thirdValue = payload.substring(secondIndex +1, thirdIndex);
String fourthValue = payload.substring(thirdIndex +1, fourthIndex);
tempIn = fourthValue.toFloat();
Serial.print(“Temp in: “);
Serial.print(tempIn);
Serial.println(“c”);
Serial.println(””);
}
void get_tempOut() {
String payload;
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare an object of class HTTPClient
http.begin("http://api.thinger.io/v1/users/[USER]/buckets/[BUCKET]/data?items=1&max_ts=0&sort=desc&authorization=[TOKEN]"); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
payload = http.getString(); //Get the request response payload
/* Serial.print(“Recived String: “);
Serial.println(payload); //Print the response payload
Serial.println(””);
*/
}
http.end(); //Close connection
}
// [{“ts”:1543332383431.0,“val”:24.25}]
int firstIndex = payload.indexOf(’:’);
int secondIndex = payload.indexOf(’,’, firstIndex +1);
int thirdIndex = payload.indexOf(’:’, secondIndex +1);
int fourthIndex = payload.indexOf(’}’, thirdIndex +1);
//String firstValue = payload.substring(0, firstIndex);
//String secondValue = payload.substring(firstIndex +1, secondIndex);
//String thirdValue = payload.substring(secondIndex +1, thirdIndex);
String fourthValue = payload.substring(thirdIndex +1, fourthIndex);
tempOut = fourthValue.toFloat();
Serial.print(“Temp out: “);
Serial.print(tempOut);
Serial.println(“c”);
Serial.println(””);
}
Thank you all for your much valued help
Regards