Ethernet

Hey friends, I am facing issue in Ethernet. 

My project code as below,

/* GR-KAEDE Sketch Template V1.15 */
#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>

void updateThingSpeak(String tsData);
void startEthernet();
// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "MWOADQ9TJ4AB6U3T";
const int updateThingSpeakInterval = 1 * 1000; // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)

// Variable Setup
long lastConnectionTime = 0;
boolean lastConnected = false;
int failedCounter = 0;

// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()
{
// Start Serial for debugging on the Serial Monitor
//Serial.begin(9600);

// Start Ethernet on Arduino
startEthernet();
}

void loop()
{
// Read value from Analog Input Pin 0
String analogValue0 = String(100, DEC);

// Print Update Response to Serial Monitor
if (client.available())
{
char c = client.read();
//Serial.print(c);
}

// Disconnect from ThingSpeak
if (!client.connected() && lastConnected)
{


client.stop();
}

// Update ThingSpeak
if(!client.connected() && (millis() - lastConnectionTime > updateThingSpeakInterval))
{
updateThingSpeak("field1="+analogValue0);
}

// Check if Arduino Ethernet needs to be restarted
if (failedCounter > 3 ) {startEthernet();}

lastConnected = client.connected();
}

void updateThingSpeak(String tsData)
{
if (client.connect(thingSpeakAddress, 80))
{
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+writeAPIKey+"\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");

client.print(tsData);

lastConnectionTime = millis();

if (client.connected())
{

failedCounter = 0;
}
else
{
failedCounter++;
}

}
else
{
failedCounter++;
lastConnectionTime = millis();
}
}

void startEthernet()
{
client.stop();
delay(500);
}

There is no response from this program.

Iot Link: https://thingspeak.com/channels/62238

Parents Reply Children
No Data