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”);
}
}