11:24 pm

January 7, 2015

below is the code which i run sucessful to upload Analogread A0 successful.
/*
| Post temp. values from a DS18B20 to ThingSpeak using the Ethercard interface based on the
| ENC28J60 chip.
| Based on the Ethercard example from http://www.jeelabs.org
| Phil Grant Jan 2014
*/
#include
// change these settings to match your own setup
#define APIKEY "xxxxxxxxxxxx" // write API key
// ethernet interface mac address, must be unique on the LAN
byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "api.thingspeak.com";
byte Ethernet::buffer[700];
uint32_t timer;
Stash stash;
void setup () {
Serial.begin(57600);
Serial.println("
[webClient]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
}
void loop () {
ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 16000; //Transmit every minute
// sensors.requestTemperatures();
delay(200);
// generate two fake values as payload - by using a separate stash,
// we can determine the size of the generated message ahead of time
byte sd = stash.create();
stash.print("field1=");
stash.println(String(analogRead (A0),DEC));
stash.save();
// generate the header with payload - note that the stash size is used,
// and that a "stash descriptor" is passed in as argument using "$H"
Stash::prepare(PSTR("POST /update HTTP/1.1" "
"
"Host: $F" "
"
"Connection: close" "
"
"X-THINGSPEAKAPIKEY: $F" "
"
"Content-Type: application/x-www-form-urlencoded" "
"
"Content-Length: $D" "
"
"
"
"$H"),
website, PSTR(APIKEY), stash.size(), sd);
// send the packet - this also releases all stash buffers once done
ether.tcpSend();
}
}
Most Users Ever Online: 114
Currently Online: Hans, agrisensezm
38 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
rw950431: 261
Vinod: 196
piajola: 85
turgo: 70
vespapierre: 63
Adarsh_Murthy: 62
Member Stats:
Guest Posters: 1
Members: 5703
Moderators: 0
Admins: 2
Forum Stats:
Groups: 4
Forums: 17
Topics: 1313
Posts: 4565
Newest Members:
Archieter, JamesExedo, IrbosHich, brodi, kasko, franklin castroAdministrators: Hans: 387, lee: 457