Serial Json read from HTTP reques to String

Hello, I’m using a weather api to get the weather conditions. I used an example from the internet to get te data from the web, this data looks like this in the serial monitor:
client readString test 11/04/13
Send an e in serial monitor to test
connected
client disconnected.
Data from server captured in readString:
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: application/json; charset=utf-8
X-StackifyID: V1|0e9b6442-6ce9-4002-a29d-7dd6a51eaf69|C59032|CD18|
Request-Context: appId=cid-v1:deb1a0bf-3522-4f78-b38f-04a889c6a745
Access-Control-Expose-Headers: Request-Context
X-Powered-By: ASP.NET
access-control-allow-origin: *
access-control-allow-headers: content-type
Date: Thu, 19 Jul 2018 19:10:04 GMT
Content-Length: 616
Via: 1.1 google
Connection: close
{“location”:{“name”:“Paris”,“region”:“Ile-de-France”,“country”:“France”,“lat”:48.87,“lon”:2.33,“tz_id”:“Europe/Paris”,“localtime_epoch”:1532027405,“localtime”:“2018-07-19 21:10”},“current”:{“last_updated_epoch”:1532026808,“last_updated”:“2018-07-19 21:00”,“temp_c”:28.0,“temp_f”:82.4,“is_day”:1,“condition”:{“text”:“Sunny”,“icon”:"//cdn.apixu.com/weather/64x64/day/113.png",“code”:1000},“wind_mph”:9.4,“wind_kph”:15.1,“wind_degree”:100,“wind_dir”:“E”,"pressure_mb":101
End of readString

this data is put in to a string called “readString”, now I want to edit this string with the second function, this is where I get stuck.The function won’t get executed on the String. Can it be because it’s JSON encoded? Can someone give a hint to a piece of code or the piece itself, so I can use the string to use the second function? This would be very handy! Thanks in advance!

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString
#include <SPI.h>
#include <Ethernet.h>
String readString;
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName = “api.apixu.com”; // myIP server test web page server
EthernetClient client;
//////////////////////
void setup(){
if (Ethernet.begin(mac) == 0) {
Serial.println(“Failed to configure Ethernet using DHCP”);
// no point in carrying on, so do nothing forevermore:
while(true);
}
Serial.begin(9600);
Serial.println(“client readString test 11/04/13”); // so I can keep track of what is loaded
Serial.println(“Send an e in serial monitor to test”); // what to do to test
Serial.println();
}
void loop(){
// check for serial input
if (Serial.available() > 0) //if something in serial buffer
{
byte inChar; // sets inChar as a byte
inChar = Serial.read(); //gets byte from buffer
if(inChar == ‘e’) // checks to see byte is an e
{
sendGET(); // call sendGET function below when byte is an e
Serial.println(“start next function”);
weatherData();
Serial.println(“done”);
delay(601000);
readString=""; //clear readString variable
}
}
}
//////////////////////////
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(serverName, 80)) { //starts client connection, checks for connection
Serial.println(“connected”);
client.println("GET /v1/current.json?key=
******************************&q=Paris HTTP/1.1"); // this is my peronal key
client.println(“Host: api.apixu.com”);
client.println(“Connection: close”); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println(“connection failed”); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
readString += c; //places captured byte in readString
}
//Serial.println();
client.stop(); //stop client
Serial.println(“client disconnected.”);
Serial.println(“Data from server captured in readString:”);
Serial.println();
Serial.print(readString); //prints readString to serial monitor
Serial.println();
Serial.println();
Serial.println(“End of readString”);
Serial.println("==================");
Serial.println();
}
void weatherData(){
Serial.print(readString);
String IncomingString = readString;
Serial.print(IncomingString);
int removeStartText = IncomingString.indexOf(“name”); //verwijder alle niet benodigde text voor de bracelet
String modifiedString = IncomingString.substring(removeStartText);
//Serial.println (b); //name’:‘Paris’,‘temp_f’:91.4,‘is_day’:0,‘condition’:{‘text’:‘Partly cloudy’,‘icon’:’//cdn.apixu.com/weather/64x64/night/116.png’,‘code’:1003},'wind_mph’:3.1
modifiedString.replace("’", “”); //verwijder alle commas
//Serial.println(modifiedString); //name:Paris,temp_f:91.4,is_day:0,condition:{text:Partly cloudy,icon://cdn.apixu.com/weather/64x64/night/116.png,code:1003},wind_mph:3.1
modifiedString.replace("{", “”); //remove all bracelets
//Serial.println(modifiedString); //
modifiedString.replace("}", “”); //remove all bracelets
//Serial.println(modifiedString); //
modifiedString.replace(“condition:”, “”); //remove “condition:”
//Serial.println(modifiedString); //
int Indextime = modifiedString.indexOf(“localtime:”);
//Serial.println(Indextime);
int IndexdoublePoint = Indextime +23;
String partOne = modifiedString.substring(0, IndexdoublePoint);
int SkipCharacter = IndexdoublePoint +1;
String partTwo = modifiedString.substring(SkipCharacter);
String fullString = partOne + “#” + partTwo;
//Serial.println(fullString); //
int Stringlenght = modifiedString.length(); //get lenght of the string
int index = 0;
int totalLoops = 0;
int indexDoublePoint;
int modifiedDoublePoint;
int indexComma;
String getDataString;
String WheatherData[40] = {};

while (index < Stringlenght){
indexDoublePoint = modifiedString.indexOf(":",index);
modifiedDoublePoint = indexDoublePoint + 1;
indexComma = modifiedString.indexOf(",",index);
getDataString = modifiedString.substring(modifiedDoublePoint,indexComma);
index = indexComma + 1;
WheatherData[totalLoops] = {getDataString};
Serial.println(WheatherData[totalLoops]);
//Serial.println(totalLoops);
//Serial.println(ModifiedDoublePoint);
//Serial.println(indexComma);
//Serial.println(getDataString);
totalLoops = totalLoops + 1;
//Serial.println(totalLoops);
Serial.println("");


}
}

This post bears a remarkable similarity to http://forum.arduino.cc/index.php?topic=558128.0

  1. You should use code tags when posting code
  2. This topic would get more attention in the forum "Programming Questions".

I suggest you use the "Report to moderator" hotspot under the post and get it moved

the json string is incomplete. use ArduinoJson library to parse a json string.