Hello again,
i am back from vacation and i have some success with my project:
Here the code:
#include "application.h"
#include "HttpClient/HttpClient.h"
STARTUP(cellular_credentials_set("internet.t-mobile","t-mobile" ,"tm" , NULL));
#define LEDPIN D7
#define LOGGING
/**
* Declaring the variables.
*/
HttpClient http;
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
{ "User-agent", "Mozilla/4.0"},
{ "Content-Type", "application/json" },
{ "Accept" , "application/json" },
//{ "Accept" , "*/*"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Particle.keepAlive(1 * 45 );
Serial.begin(9600);
pinMode(LEDPIN, OUTPUT);
Particle.subscribe("Button_1", myHandler, MY_DEVICES);
Particle.subscribe("High", myHandler, MY_DEVICES);
Particle.subscribe("getUsage", getUsageHandler, MY_DEVICES);
}
void loop() {
}
void publish_messages(String message, int delay_in_ms)
{
Particle.publish(message);
delay(delay_in_ms);
}
void get_usage()
{
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "pass.telekom.de";
request.port = 80;
request.path = "/api/service/generic/v1/status";
// The library also supports sending a body with your request:
//request.body = "{\"key\":\"value\"}";
// request.body = "{\"usedVolumeStr\":\"value\"}";
request.body = "{\"usedVolumeStr\":}";
// Get request
http.get(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
publish_messages(String(response.status) ,1000);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
String output = response.body;
publish_messages(output ,1000);
}
void getUsageHandler(const char *event, const char *data)
{
get_usage();
}
i get the following response from the server:
**Application> Start of Loop.**
**Application> Response status: 200**
**Application> HTTP Response Body: {"nextUpdate":300,"subscriptions":["tns","xtraSpeed"],"title":"Xtra SpeedOn","passName":"Ihr Monatsvolumen","passStage":1,"validityPeriod":4,"initialVolume":104857600,"initialVolumeStr":"100 MB","usedVolume":460800,"usedPercentage":1,"usedVolumeStr":"450 kB","usedAt":1467042910000,"remainingSeconds":2614864,"downSpeed":7200,"downSpeedStr":"7,2 Mbit/s"}**
Now my next question:
How can i parse the response to get only the āusedVolumeStrā:ā450 kBā Key??
Thanks a lot
Stivi