Can a device read data from an endpoint?

Hi.

I am exploring some use of endpoint in different cases. I have to say that endpoints is a very nice feature with getting push notifications on the phone and so on. But still there is something a cant figure out.

I have noeticed that if I set up a HTTP endpoint, I have the option to use GET.
Now the thing is, i know i can communicare between devices but then i need to reprogram all of them.

So i was wondering if there is any way to use a GET request to the device recourse, and call the endpoint and retrive the data on a device?
If so, please let me know how to do this. It would be much easier then to reprogram all the devices everytime i want to share data between them.

Kind regards :slight_smile:

Hello @glennern,

Unfortunately, right now this feature is not available yet. You will have to use your own client to call that webhook.

Best

Thank you for your answer. Hope it this is something that will be availible in the future, it wolud be very usefull :smiley:

Kind regards

It will! It is in the ToDo list :wink:

If you just want to retrieve data on a device, I think you can apply this tutorial

There is a way to access device’s resources by a link, and it responds by a json array, and with that tutorial you can get data of devices without programming all of them, just programming the one that needs to get the data.

Hope this helps

1 Like

Thank you for this small tutorial :smiley:

I had to change some of the code, but i can now get data from the bucket, but i still have to get it parsed.
As you probably have figured out, i am not very good at programming and have a long way to go. But in small steps im getting there :stuck_out_tongue:

So far the Thinger.io experince have been very fun, and i have got hooked on IoT. Its realy fun geting all kindes of devices talking to the internet.
I’m also very thankfull for the comunity support. It makes me learn new things every day.

Kind regards

It has a function to extract the specific variable you want to read, and I’ve checked and there is a way to consult a device resource and it will give you an answer as a json array

https://api.thinger.io/v2/users/[USER]/devices/[DEVICE]/[RESOURCE?authorization=[AUTH_TOKEN]

Replace the fields into brackets (and of course without them) and you should see the specific resource, you can try it in a web browser and you will be consulting directly the device.

With a link of that kind and the previous tutorial, you can access any variable of a device from a new device without programming the previous one, of course it is not a native thinger.io’s native function.

Is that what you are looking for?

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 :stuck_out_tongue:

#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 :smiley:

Regards

BTW, this project s all about making a thermometer with a hidden button to control the beer fridge. This way it is always accessible and a i can adjust the beer temperature with the button hidden i plain sight (so my girlfriend dont get angry about another one of my “silly” projects). :sunglasses:
Working on a case design to 3D print so i can paint it and put the device in the hall, and then finish the code :yum:

Cheers

Cool!

Btw in the tutorial there is a parsing function :wink:

But if you get it working by your way, that’s the idea

The parsing in the tutorial did not work for some reason. Most likely a error in the user end of my keyboard :rofl:
So thats why i needed to parse it myself.

I realy appreciate the help :grinning:

That’s weird, but it is nice that you could sort your issue.