HTTP/1.1 200 OK
Server:Apache Tomcat/5.0.12
Date:Mon,6Oct2003 13:23:42 GMT
Content-Length:112
data(返回数据)
#include <ThingSpeak.h>
#include <ESP8266WiFi.h>
//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>
#define grayscalePin D8
// Network Parameters
const char* ssid = "DFRobot-guest";
const char* password = "dfrobot@2017";
// ThingSpeak information
char thingSpeakAddress[] = "api.thingspeak.com";
const char* server = "api.thingspeak.com";
unsigned long channelID = 541489;
char* readAPIKey = "TY5KLRMTB5E311RX";
char* writeAPIKey = "J1XHZ98DG0PGHKGW";
String apiKey = "TY5KLRMTB5E311RX";
const unsigned long postingInterval = 120L * 1000L;
unsigned int FieldLabelone= 1; // Field to write temperature data
unsigned long lastConnectionTime = 0;
long lastUpdateTime = 0;
WiFiClient client;
float readTSData( long TSChannel,unsigned int TSField ){
float data = ThingSpeak.readFloatField( TSChannel, TSField, readAPIKey );
Serial.println( " Data read from ThingSpeak: " + String( data, 9 ) );
return data;
}
// Use this function if you want to write a single field
int writeTSData( long TSChannel, unsigned int TSField, float data ){
int writeSuccess = ThingSpeak.writeField( TSChannel, TSField, data, writeAPIKey ); // Write the data to the channel
if ( writeSuccess ){
Serial.println( String(data) + " written to Thingspeak." );
}
return writeSuccess;
}
//use this function if you want multiple fields simultaneously
int write2TSData( long TSChannel, unsigned int TSField1, float field1Data, unsigned int TSField2, long field2Data, unsigned int TSField3, long field3Data ){
ThingSpeak.setField( TSField1, field1Data );
ThingSpeak.setField( TSField2, field2Data );
ThingSpeak.setField( TSField3, field3Data );
int writeSuccess = ThingSpeak.writeFields( TSChannel, writeAPIKey );
return writeSuccess;
}
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
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");
}
void loop()
{
int val = analogRead(A0);
delay(100);
if (client.connect(server,80)) { // "184.106.153.149" or api.thingspeak.com