Hello guys,
now in the holly-days vacation I started again to play with the Arduino boards (WeMos ESP8266 D1 mini) and sensors I purchased long ago, I wanted to be able to start some 10meters led strip from my phone, and also monitor temperature, the plan is to make the light go on automatically when somebody enters in the office, and the ambient light is low enough .. but this is another story.
I Started from the AdvancedWebServer example and wanted to make the homepage looking better, I done it and it looks quite nice but some of the data in the homepage (temperature graphs) are hardcoded
// the next line is ok, it shows the real temperature
server.sendContent(String("<h2 class='value'>") + celsiusTemp + "°C</h2>" );
//this line is just outputing to a browser some values, and I wanted to get them from my database
server.sendContent( " <span class='line'>5,3,2,-1,-3,-3,-5,-6,-9,-10,-5,-3,-2,2,3,5.5,8,7,6,9,5,8,9,8,9,8,9,8,9,8,6,5,3,2,1,0,-2,-3,-5</span> "
);
Attached is the dashboard, I'm happy how it looks on both PC or mobile devices, the button to turn on / OFF the lights changes it's color and also the icon when the light is turned on / off, but I need some help with the function the gets the response from the server. The server response is done and it looks like this :
The header in the php file sets the Content-Type: text/plain, and all the output looks like this:
20.10,20.10,20.00,19.80,19.60,20.00,19.90,19.60,19.70,20.00,19.90,19.80,20.00,20.10,20.80,22.70,22.70,22.50,22.50,22.50,22.40,22.30,22.20,21.70,21.90,21.80,21.60,21.40,21.20,21.20
The arduino request to the server looks like this
String TempGraph;
static char HumidityGraph[30];
void handleRoot() {
..
// get temperature graph
getTemperatureMiniGraph(TempGraph);
..
}
void getTemperatureMiniGraph(String &dest)
{
WiFiClient client; //Instantiate WiFi object
//Start or API service using our WiFi Client
if (client.connect(WEBSITE, 80))
{
client.print("GET /getdata.php?type=minigraph&devid=" + devid
+ "&value=temperature"
);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(WEBSITE);
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: close");
client.println();
}
delay(10);
// Read all the lines of the reply from server and print them to Serial
Serial.println("Respond:");
while(client.available()){
String line = client.readStringUntil('\r');
Serial.print(line);
// I will neeed to filter the headers, but first I want to be able to write to TempGraph anything
}
// strcpy(dest, line); // I tryed with this but I get an error
//TempGraph = line; // also this returns an error
String testline = "someline"; // this works, it modify the String and I see this text in the homepage
TempGraph = testline;
}
So my first request to you guys is to help me out understand what I'm doing wrong and why I get the error 'line' was not declared in this scope, how can I modify the String TempGraph everytime I call the getTemperatureMiniGraph function?
Thank you.