When I look at the serial console I get this:
** IDLE **
Send ACK to SYNACK **
Envoie les donnes au serveur
Send ACk **
Send FinACk **
Send ACk **
Send FinACk **
Send ACk **
** IDLE **
Send ACK to SYNACK **
Envoie les donnes au serveur
Send ACk **
Send FinACk **
Send ACk **
Send FinACk **
Send ACk **
** IDLE **
Send ACK to SYNACK **
Envoie les donnes au serveur
Send ACk **
Send FinACk **
Send ACk **
Send FinACk **
Send ACk **
** IDLE **
Send ACK to SYNACK **
Envoie les donnes au serveur
Send ACk **
Send FinACk **
Arp Reply ** <------- here "save.php" on the server doesn't get updated anymore
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
Arp Reply **
The code that I'm using is this one:
#include "etherShield.h"
#define TEMP_PIN 14 // DS18B20 de data pin pullup met 4k7 Ohm
// ARDUINO
// Addresse MAC de l'arduino
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24};
// Adresse IP de l'arduino
static uint8_t myip[4] = {192,168,1,86};
static char client_ip[] = "192.168.1.86";
// PORT Ethernet Client
static uint16_t my_port = 1200;
// SERVEUR
// Adresse IP du serveur
static uint8_t dest_ip[4]={88,88,199,105}; // <-- Put IP of your Server
// Adresse MAC du serveur ou du routeur si le serveur n'est pas dans le même sous réseau (exemple, un serveur sur internet)
static uint8_t dest_mac[6]={0x00,0x1d,0x68,0xf5,0x60,0xd6}; // <-- Put MAC Adresse of your personnal router
// Machine a état da la partie cliente
enum CLIENT_STATE {IDLE, ARP_SENT, ARP_REPLY, SYNC_SENT};
static CLIENT_STATE client_state;
static uint8_t client_data_ready;
static uint8_t syn_ack_timeout = 0;
static uint16_t watchdog = 0;
void OneWireReset(int Pin);
void OneWireOutByte(int Pin, byte d);
byte OneWireInByte(int Pin);
int HighByte, LowByte, TReading, SignBit, Tc_100, whole, sign, fract;
void OneWireReset(int Pin) // reset. Should improve to act as a presence pulse
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT); // bring low for 500 us
delayMicroseconds(500);
pinMode(Pin, INPUT);
delayMicroseconds(500);
}
void OneWireOutByte(int Pin, byte d) // output byte d (least sig bit first).
{
byte n;
for(n=8; n!=0; n--)
{
if ((d & 0x01) == 1) // test least sig bit
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(60);
}
else
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(60);
pinMode(Pin, INPUT);
}
d=d>>1; // now the next bit is in the least sig bit position.
}
}
byte OneWireInByte(int Pin) // read byte, least sig byte first
{
byte d, n, b;
for (n=0; n<8; n++)
{
digitalWrite(Pin, LOW);
pinMode(Pin, OUTPUT);
delayMicroseconds(5);
pinMode(Pin, INPUT);
delayMicroseconds(5);
b = digitalRead(Pin);
delayMicroseconds(50);
d = (d >> 1) | (b<<7); // shift d to right and insert b in most sig bit position
}
return(d);
}
void ReadTemps(){
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);
LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
whole = Tc_100 / 100; // separate off the whole and fractional portions
}
void getCurrentTemp(char *temp)
{
// int HighByte, LowByte, TReading, Tc_100, sign, whole, fract;
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0x44); // perform temperature conversion, strong pullup for one sec
OneWireReset(TEMP_PIN);
OneWireOutByte(TEMP_PIN, 0xcc);
OneWireOutByte(TEMP_PIN, 0xbe);
LowByte = OneWireInByte(TEMP_PIN);
HighByte = OneWireInByte(TEMP_PIN);
TReading = (HighByte << 8) + LowByte;
sign = TReading & 0x8000; // test most sig bit
if (sign) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
whole = Tc_100 / 100; // separate off the whole and fractional portions
fract = Tc_100 % 100;
if(sign) temp[0]='-';
else temp[0]='+';
temp[1]= (whole-(whole/100)*100)/10 +'0' ;
temp[2]= whole-(whole/10)*10 +'0';
temp[3]='.';
temp[4]=fract/10 +'0';
temp[5]=fract-(fract/10)*10 +'0';
temp[6] = '\0';
}
#define BUFFER_SIZE 500
static uint8_t buf[BUFFER_SIZE+1];
char sensorData[10];
EtherShield es=EtherShield();
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf);
int8_t analyse_cmd(char *str);
void client_process(void);
// ********** SETUP ********** //
void setup(){
// Initialise la liaison série pour le Terminal
Serial.begin(9600);
Serial.println("~~~ Debut SETUP ~~~");
// Initialise le enc28j60 (Contrôleur Ethernet)
es.ES_enc28j60Init(mymac);
es.ES_enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
delay(10);
/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
// LEDA=greed LEDB=yellow
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
// 0x880 is PHLCON LEDB=on, LEDA=on
// enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x880);
delay(500);
//
// 0x990 is PHLCON LEDB=off, LEDA=off
// enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
es.ES_enc28j60PhyWrite(PHLCON,0x990);
delay(500);
//
// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
es.ES_enc28j60PhyWrite(PHLCON,0x476);
delay(100);
//init the ethernet/ip layer:
es.ES_init_ip_arp_udp_tcp(mymac,myip,80);
// intialize variable;
syn_ack_timeout =0;
client_data_ready = 0;
client_state = IDLE;
Serial.println("~~~ Fin SETUP ~~~");
}
// ********** MAIN LOOP ********** //
void loop()
{
if(client_data_ready==0)
{
// Lecture de la T° toute les 10 secondes
delay(1000UL); // 10 sec.
client_data_ready = 1; // Indique que le client est prêt a transmettre ses données
}
getCurrentTemp(sensorData);
client_process();
}
// ********** Generation de la Req. Client ********** //
uint16_t gen_client_request(uint8_t *buf )
{
Serial.println("Envoie les donnes au serveur");
uint16_t plen;
byte i;
plen= es.ES_fill_tcp_data_p(buf,0, PSTR ( "GET /ethershield_log/save.php?pwd=secret&client=" ) );
for(i=0; client_ip[i]!='\0'; i++)
{
buf[TCP_DATA_P+plen]=client_ip[i];
plen++;
}
plen= es.ES_fill_tcp_data_p(buf,plen, PSTR ( "&status=" ) );
for(i=0; sensorData[i]!='\0'; i++){
buf[TCP_DATA_P+plen]=sensorData[i];
plen++;
}
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( " HTTP/1.0\r\n" ));
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Host: www.luma.nl\r\n" )); //<-- Put your web site adresse
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "User-Agent: AVR ethernet\r\n" ));
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Accept: text/html\r\n" ));
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Keep-Alive: 300\r\n" ));
plen= es.ES_fill_tcp_data_p(buf, plen, PSTR ( "Connection: keep-alive\r\n\r\n" ));
return plen;
}
//*****************************************************************************************
//
// Function : client_process
// Description : send temparature to web server, this option is disabled by default.
// YOU MUST install webserver and server script before enable this option,
// I recommented Apache webserver and PHP script.
// More detail about Apache and PHP installation please visit http://www.avrportal.com/
//
//*****************************************************************************************
// ********** Gere la communication Ethernet du Client ********** //
further in next post...