Iâm reading a book internet of things with intel galileo. There is a tutorial on how to plot on plotly using arduino IDE. Iâm connecting with wifi. I downloaded the code, but always when I run the sketch, I get Couldnât connect to plotlyâs REST servers.
Thank you very much.
#include <SD.h>
#include <WiFi.h>
char ssid[] = âHOMEâ; // your network SSID (name)
char pass[] = âxxxxxxxxxxâ; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
WiFiClient client;
String username = âanatoliy17â;
String api_key = âxxxxxxxxxxxxxxxxâ;
String temperaturesY = â[â;
String timesX = â[â;
int seconds = 0;
void setup() {
system(âifup wlan0â);
delay(1000);
Serial.begin(9600);
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println(âConnected to wifiâ);
Serial.println(âStarting SD cardâŠâ);
if (!SD.begin()) {
Serial.println(âSD card failed to start!â);
return;
}
Serial.println(âSD card started successfulyâ);
delay(5000);
system(âtouch /media/realroot/sample.tmpâ);
}
void loop() {
//If Plotly response
if (client.available()) {
char c = client.read();
Serial.print©;
}
//Collect samples
if (seconds <= 60) {
system(âecho $((cat /sys/class/thermal/thermal_zone0/temp
/ 1000)) > /media/realroot/sample.tmpâ);
getSamples();
delay(1000);
++seconds;
}
//Stop collecting samples and request chart
if (seconds == 61) {
Serial.println(âAll data collected!! Plotting chart!â);
plotChart();
}
}
//Chart request method
void plotChart(){
if (!client.connect(âplot.lyâ, 80)) {
Serial.println("⊠Couldnât connect to plotlyâs REST servers⊠");
return;
}
Serial.println(âConnected to plotlyâs REST serversâ);
Serial.println(âSending HTTP Post to plotlyâ);
client.println(âPOST /clientresp HTTP/1.1â);
//client.println(âHost: 107.21.214.199â);
client.println(âHost: plot.lyâ);
client.println(âUser-Agent: Galileo/0.0.1â);
client.print("Content-Length: ");
int content_length = 276 + username.length() + api_key.length() + temperaturesY.length() + timesX.length();
client.println(content_length);
client.println();
client.print(âversion=2.3&origin=plot&platform=Galileo&un=â);
client.print(username);
client.print("&key=");
client.print(api_key);
client.print("&args={âxâ:");
client.print(timesX);
client.print(",âyâ:");
client.print(temperaturesY);
client.print(",âtypeâ:âscatterâ,âmodeâ:âlines+markersâ,âvisibleâ:true}&kwargs={âfilenameâ:âgalileo_temperatureâ,âfileoptâ:âoverwriteâ,âstyleâ:{âtypeâ:âlineâ},âlayoutâ:{âtitleâ:âGalileo CPU Temperatureâ},âworld_readableâ:true}");
client.println();
Serial.println(âRequest sent. Waiting responseâŠâ);
}
//Samples collector
void getSamples(){
if (SD.exists(âsample.tmpâ)) {
File myFile = SD.open(âsample.tmpâ);
if (myFile) {
String value;
while (myFile.available()) {
value += (char)myFile.read();
}
myFile.close();
value.trim();
Serial.print("Value read x:");
Serial.print(seconds);
Serial.print(", y:");
Serial.println(value);
temperaturesY += value;
timesX += seconds;
if(seconds < 60){
timesX += ",";
temperaturesY += ",";
} else {
timesX += "]";
temperaturesY += "]";
}
}else {
Serial.println("Failed to read file");
}
}else {
Serial.println(âFile doesnât existâ);
}
}