EDIT:
I just ran the code at https://github.com/squix78/esp8266-proj ... logger.ino
Putting in my key and hard-coding some values, GETing every 60 seconds, and I can only connect once successfully.
The modified code (- keys):
/*
* This sketch sends data via HTTP GET requests to thingspeak service every 10 minutes
* You have to set your wifi credentials and your thingspeak key.
*/
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}
const char* ssid = "Virgin Mobile 4G_38AB4B";
const char* password = "XXX";
const char* host = "api.thingspeak.com";
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(5000);
}
int value = 0;
void loop() {
++value;
logThingSpeak(value);
delay(60000);
}
void logThingSpeak(int value) {
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
String url = "/update?api_key=XXX&field1=" + String(value);
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(10);
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection. ");
}
Serial output:
Opening port
Port open
Connecting to Virgin Mobile 4G_38AB4B
.
WiFi connected
IP address:
192.168.0.134
connecting to api.thingspeak.com
Requesting URL: /update?api_key=XXX&field1=1
closing connection.
connecting to api.thingspeak.com
connection failed
connecting to api.thingspeak.com
connection failed
connecting to api.thingspeak.com
connection failed
connecting to api.thingspeak.com
connection failed
The same result if I GET every 2 minutes.