Hi Guy´s. I´m new on the Arduino world and currently I´m trying to let my arduino read Temperature from a Sensor and send the Value over the Lan to my Linux Server and write it down to a prepared MySQL DB. I´ve prepared a PHP Script who write to the DB. All my little Arduino needs to do is do a HTTP Request
"p.e. http://my-server/arduino/send_data.php?TEMP=value". Okay that sounds very simple and with the original Arduino Ethernet Shield, this shouldn´t be a Problem but I have the cheaper Version who called "EtherShield". I´ve downloadet the latest Version of the Librarie on Google Code and I´ve tried one of the Examples who works fine. I was able to Ping the Device and I was able to connect to the Device (with the Webserver Example).
Now I´ve googled a bit and find a dummy source on "Andy´s Life" Webpage who should do exactly what I want do. I´ve changed the Values to fit to my Network and I´ve deleted the part of his Code where he is reading his Sensor Data.
All my Code should do now is reply to a Ping Request and sending every 30 Secondes "123456" to my Database. Ok so far so good. Here is my Code:
#include <etherShield.h>
static uint8_t mymac[6] = {0xAA,0x55,0x58,0x10,0x00,0x24}; //Shields Mac Address
static uint8_t myip[4] = {192,168,1,222}; //Arduino's IP Address
static uint8_t gwip[4] = {192,168,1,1}; //Arduino's Gateway Address
static uint8_t webip[4] = {192,168,1,2}; //Server's IP Address
// The name of the virtual host which you want to contact at webip (hostname of the first portion of the URL):
#define WEB_VHOST "192.168.1.2" //Virtual Host Name of the Server
#define WEBURL "/arduino/send_data.php?TEMP=123456" //PHP Script Location
#define MYWWWPORT 80
static volatile uint8_t start_web_client=0; // 0=off but enabled, 1=send update, 2=sending initiated, 3=update was sent OK, 4=diable updates
static uint8_t web_client_attempts=0;
static uint8_t web_client_sendok=0;
static uint8_t resend=0;
#define STATUS_BUFFER_SIZE 50
#define BUFFER_SIZE 650
static uint8_t buf[BUFFER_SIZE+1];
// Instantiate the EtherShield class
EtherShield es=EtherShield();
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
uint16_t plen;
plen = es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<h1>Temp/Humidity Monitor</h1><pre>\n"));
return(plen);
}
// Browser callback, where we get to after receiving a reply to an update, should really
// do somthing here to check all was OK.
void browserresult_callback(uint8_t statuscode,uint16_t datapos){
if (statuscode==0){
web_client_sendok++;
}
// clear pending state at sucessful contact with the
// web server even if account is expired:
if (start_web_client==2) start_web_client=3;
}
// Perform setup on ethernet and oneWire
void setup(){
// initialize enc28j60
es.ES_enc28j60Init(mymac);
//init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
// init the web client:
es.ES_client_set_gwip(gwip); // e.g internal IP of dsl router
}
// The business end of things
void loop(){
uint16_t dat_p;
int8_t cmd;
start_web_client=1;
unsigned long lastSend = millis();
unsigned long time;
while(1){
// handle ping and wait for a tcp packet
dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if(dat_p==0){
time = millis();
if( time > (lastSend + 30000) ) {
resend=1; // resend once if it failed
start_web_client=1;
lastSend = time;}
if (start_web_client==1) {
es.ES_client_set_wwwip(webip);
es.ES_client_browse_url(PSTR(WEBURL),PSTR(WEB_VHOST),NULL, &browserresult_callback);
start_web_client=2;
web_client_attempts++; }
continue; }
dat_p=print_webpage(buf);
es.ES_www_server_reply(buf,dat_p); // send data
} }
Okay. If I write this to my Arduino, it seams that he just make nothing. The Board don´t answer my Ping Requests, It don´t call the PHP Script, It don´t create his Website yeah it even don´t try to connect to the Server (seen Apache log files).
If you have any Ideas for my Problem, I would be very Happy
Thanks a lot Friends