Software Serial Buffer Overflow ?

Bonjour,

Je m’arrache les cheveux sur,semble t’il, un problème de buffer overflow.

Présentation hardware et software:
Capteurs + Actuateurs <—> Arduino Duemilanove <—> Xport Direct + <—> WAMP (PHP, JS & Google JS)

J’ai un ensemble de capteurs I2C, OneWire qui sont scrutés, je compile les valeurs et envois une requête GET vers un fichier PHP qui s’occupe de logger les données dans une BDD
Dans ce sens pas de problème.
Le serveur renvoie un Header de la forme:

						HTTP/1.1 200 OK
							Date: Mon, 06 May 2013 12:48:45 GMT
							Server: Apache/2.2.22 (Win32) PHP/5.4.3
							X-Powered-By: PHP/5.4.3
							Content-Length: 1
							Connection: close
							Content-Type: text/html

que je veux intercepter.

La connexion série entre le module Xport Direct+ l’uC est émulée via la librairie “SoftwareSerial” en 19200 bauds.
J’écoute donc le port série émulé après chaque requête GET

	void WaitingForData()
		{
		byte theByte;
		String theString = "";
		char character;
		int InterrogationPosition = 0;
		//Wait for answer

		while(!XPORT_Serial.available()) {} // Just loop until available
		
		while (XPORT_Serial.available())
			{	
			character = XPORT_Serial.read();
			theString += character;
			}
		Serial.println(theString);
		InterrogationPosition = theString.indexOf('?');
		//Test http answer
		if (theString.startsWith("200 OK", 9))
			{
			Serial.println("Got an OK from the server"); 
			}
		//test xmlhttprequest GET, si la position du '?' est supérieure à 0
		else if (InterrogationPosition != 0)
			{
			//Envoi d'une réponse
			//XPORT_Serial.print(HTTP_HEADER);
			Serial.println("Got a command");
			}
		else
			{
			Serial.println("No OK from server"); 
			xportReset();
			}
                }

Bilan:
Je n’arrive pas à lire l’Header envoyé en entier, le Serial.println(theString); affichant par exemple :

HTTP/1.1 200 OK
Date: Fri, 31 May 2013 14:03:55 GMT
Server: Apache/2.2.22 (Win32) PHP/5.4.3
X-Powered-By: PHP/5.4.3
Content-Len:s e

ou

HTTP/1.1 200 OK
Date: Fri, 31 May 2013 14:04:03 GMT
Server: Apache/2.2.22 (Win32) PHP/5.4.3
X-Powered-By: PHP/5.4.3
Content-Lent:ya

Bref, il me manque une bonne partie de la réponse ce qui est sacrément embêtant !

Pour info, dans la librairie SoftwareSerial, j’ai augmenté la taille du buffer en ligne 42 #define _SS_MAX_RX_BUFF 128
J’ai essayé une valeur supérieure puissance de 2 (2^n) telle que 256 mais dans ce cas les caractères sont corrompus.

J’ai des interruptions qui sont générées par Timer1, le fait de désactiver les interruptions ne change rien.

Bref, malgré des recherches sur le Net (du style si softwareserial buffer passé à 256 mettre static volatile uint16_t _receive_buffer_tail & static volatile uint16_t _receive_buffer_head ) je n’arrive pas à trouver le problème.

Je sens une solution toute bête mais la je ne trouve pas !

Ps: IDE 1.0.4

bonjour, question bête, mais pourquoi demander confirmation du server? sinon regarde du coté de strcmp je crois, dès que tu trouve 200, tu passe à la suite.

Une requête GET permet d'envoyer des données mais aussi d'en recevoir et dans ce cas, les données renvoyées sont après l'entête.

si tu mettais tout ton code, ca serait plus simple. par contre relis ce que j'ai mis, si tu veux juste choper le 200, pas la peine de tout prendre ;)

Ps : ne pas raisonner forcément en mode php avec arduino

Je viens d'essayer ce code :

    void WaitingForData()
        {
                uint8_t idx=0;
                char c;
                byte linebuffer[256];
                
                
                while(!XPORT_Serial.available()) {} // Just loop until available
                while (XPORT_Serial.available())
                {
                  c = XPORT_Serial.read();
                  linebuffer[idx++] = c;
                  if (idx == 256)
                    {
                    break;
                    }
                }
                  Serial.write(linebuffer,256);
        }

Qui bien sur ne me donne pas satisfaction, le résultat étant le même.

Le code complet :

//Arduino IDE 1.0.4
//Arduino Duemilanove wth 4 sensors HIH6130 + DHT11 + DS18B20 + DS1621 + LDR
//Send Sensors values throught ethernet via Lantronix Xport Direct+

//HIH6130 > I2C Humidity and Temperature Sensor 1.2 %RH over five years & ±5 %RH > Use of Wire.h library *** Datasheet http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Prototyping/1443945.pdf
//DHT11 > Humidity and Temperature Sensor > Use of DHT.h library *** Datasheet http://www.micro4you.com/files/sensor/DHT11.pdf
//DS19B20 > One-wire Temperture Sensor -55°C to +125°C accurate to ±0.5°C over the range of -10°C to +85°C. > Use of OneWire.h library *** Datasheet http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf
//DS1621 > I2C Temperature Sensor -55°C to +125°C accurate to ±0.5°C over the range of -10°C to +70°C with 3,0V<VDD<5,0V > Use of Wire.h library *** Datasheet http://pdfserv.maximintegrated.com/en/ds/DS1621.pdf
//Xport Direct+ > Embedded Device Server see "http://www.lantronix.com/device-networking/embedded-device-servers/xport-direct-plus.html" > Use of SoftwareSerial.h library

//Credit to :
//			- http://www.phanderson.com/arduino/hih6130.html for HIH6130
//			- http://www.pjrc.com/teensy/td_libs_OneWire.html for OneWire library
//			- http://www.ladyada.net/make/eshield/index.html for Xport Direct+
//			- http://learn.adafruit.com/dht for DHT11
//			- http://skyduino.wordpress.com/2012/04/26/arduino-capteur-de-temperature-ds18b20/ for DS18B20
//			- To me for DS1621

//Program structure
//	1.Initialization of the Serial Port > Just for be sure that everything is good
//	2.Initialization of the Xport serial > Ready to send values
//	3.Loop with call of the different sensor to read values and write them in varaibles
//	4.Create string with comma seprator to send values throught Xport Direct+ -> "HIH-6130,Humidity_value,Temperature_value,/,DHT-11,Humidty_value,Temperature_value,/,DS18B20,Temperature_value"

//Libraries use
	#include <avr/io.h>
	#include <avr/interrupt.h>
	#include <Wire.h>
	#include <DHT.h>
	#include <OneWire.h>
	#include <SoftwareSerial.h>		//Line 42 RX buffer size : #define _SS_MAX_RX_BUFF 128
	#include <Timer.h>
	
//Define use of Arduino Pins
//				- For Xport Direct+ :
//							- XPort RX pin -> Arduino digital pin 2 > This is the pin that the XPort uses to receive data. It is necessary!
//							- XPort TX pin -> Arduino digital pin 3 > This is the pin that the XPort uses to send data. It is necessary!
//							- XPort Reset pin -> Arduino digital pin 4 > This is the pin that is used to reset the XPort. It is necessary!
// 							- XPort DTR pin -> Arduino digital pin 5 > This is the pin that the XPort uses to tell the Arduino that the Internet connection has ended. Its not essential but its very useful
//							- XPort CTS pin -> Arduino digital pin 6 > This is the pin that the Arduino uses to keep the XPort from overwhelming it with data. Its not essential but its very, very strongly recommended
//							- XPort RTS pin -> Arduino digital pin 7 > This is the pin that the XPort uses to tell the Arduino that there is more data available. Its not used in my examples but it might be useful for some people.
//				- For HIH6130 = I2C :
//							- SCL -> Arduino analog pin 5
//							- SDA -> Arduino analog pin 4
//							- Power ON HIH6130 -> Arduino digital pin 8
//				- For DHT11 :
//							- DHT11 Data Pin 2 -> Arduino digital pin 9
//				- For DS18B20 :
//							- DQ Pin -> Arduino digital pin 10
//				- For DS1621 = I2C :
//							- SCL -> Arduino analog pin 5
//							- SDA -> Arduino analog pin 4
//							- Power ON DS1621 -> Arduino digital pin 8
//				- For the LED :
//							- Arduino digital pin 12

//So:

// These are web server specific values
	#define PHP_PAGE_LOCATION "/Temperatures/xPortTest.php"
	#define WEB_HOST "Host: http://localhost"
	#define IP_AND_PORT "C192.168.1.15/80\n"
	#define HTTP_HEADER "HTTP/1.0 200 OK\nServer: Arduino\nContent-Type: text/html\n\n"



//	- For Xport Direct+ :
		#define XPORT_RXPIN 2
		#define XPORT_TXPIN 3
		#define XPORT_RESETPIN 4
		#define XPORT_DTRPIN 5
		#define XPORT_CTSPIN 6
		#define XPORT_RTSPIN 7	//Not used
//	- For HIH6130 Power On :
		#define HIH_POWER_Pin 7
//	- For DHT11 :
		#define DHT_Pin 8
//	- For DS18B20 :
		#define One_Wire_Pin 9
//	- For DS1621 :
//		Nothing
//	- For LDR :
		#define LDR_Pin A0
//	- For the Led emulating the Fogger:
		#define Fogger_Pin 12
//	- For the Led emulating the Light:
		#define Light_Pin 10
	
//Define Sensors address / type and commands
//	- For Xport Direct+ :
//		Nothing to do
//	- For HIH6130 the HIH family code is 0x27 (see http://sensing.honeywell.com/index.php?ci_id=142171)
		#define HIH6130 0x27
		
//	- For DHT we can choose between 3 DHT Sensors Type so uncomment the right one :
		#define DHTTYPE DHT11   // DHT 11 
//		#define DHTTYPE DHT22   // DHT 22  (AM2302)
//		#define DHTTYPE DHT21   // DHT 21 (AM2301)

//	- For DS18B20 the DS18B20’s 1-Wire family code is 28h (hexadecimal) :
		#define DS18B20 0x28
//		DS18B20 commands
		#define DS18B20_Convert_T 0x44
		#define DS18B20_READ_SCRATCHPAD 0xBE
		
//	- For DS1621 the DS1621’s I2C family code is 1001XXXY if A2, A1, A0 to ground XXX=000, if A2 to VDD XXX=100 and Y = 1 to read and 0 to write :
		#define DS1621 0x90
		#define DS1621_A2_A1_A0 0x00
//		DS1621 commands
		#define DS1621_Read_Temperature 0xAA
		#define DS1621_Access_TH 0xA1
		#define DS1621_Access_TL 0xA2
		#define DS1621_Access_Config 0xAC
		#define DS1621_Read_Counter 0xA8
		#define DS1621_Read_Slope 0xA9
		#define DS1621_Start_Convert_T 0xEE
		#define DS1621_Stop_Convert_T 0x22
		#define DS1621_Register_Value 0x00
//		DS1621 register values
		//Configuration register
		//	MSb		Bit6	Bit5	Bit4	Bit3	Bit2	Bit1	LSb
		//	Done	THF		TLF		NVB		X		X		POL		1SHOT
		//	0		0		0		0		0		0		1		1
		#define DS1621_Config_Reg 0x03
		
//Define others constants
		#define TRUE 1
		#define FALSE 0
//		Serial PORTS Bauds rate
		#define Arduino_Serial_Speed 57600
		#define Xport_Serial_Speed 19200

//Object instanciation
//As we use libraries we can instanciate them so for:
//	- Xport Direct+ > Object name = XPORT_Serial
		SoftwareSerial XPORT_Serial(XPORT_TXPIN, XPORT_RXPIN);
//	- HIH6130 > Object name = Wire as Wire can not be instantiate

//	- DHT11 > Object name = DHT_Sensor
		DHT DHT_Sensor(DHT_Pin, DHTTYPE);
//	- DS18B20 > Object name = DS18B20_Sensor
		OneWire DS18B20_Sensor(One_Wire_Pin);

//Declaration of functions
//	-For HIH6130:
		boolean get_HIH_values(unsigned int *HIH_Hum, unsigned int *HIH_Temp);
		byte fetch_humidity_temperature(unsigned int *Raw_Hum, unsigned int *Raw_Temp);
//	-For DHT11:
		boolean get_DHT_values(float *DHT_Hum, float *DHT_Temp);
//	-For DS18B20
		boolean get_DS18B20_value(float *DS18B20_Temp);
//	-For DS1621
		boolean DS1621_Configuration(byte Generic_Address, byte Pin_Config);
		boolean get_DS1621_value(float *DS1621_Temp);
		byte get_DS1621_Register_value(byte address);
		byte get_DS1621_Address(byte Generic_Address, byte Pin_Config);
//	-For LDR
		int get_LDR_Value();
	
//	For Fogger and Illumination Interrupt
	volatile int second = 0;
	volatile int sec_for_min = 0;
	volatile int minute = 0;
	//Fogger
	volatile int Fogger_Time_Down_Elapsed = 0;	//Unit seconds
	volatile int Fogger_Time_Up_Elapsed = 0;	//Unit seconds
	volatile boolean Fogger_Down = false;
	volatile boolean Fogger_Up = false;
	//Light
	volatile int Light_Time_Down_Elapsed = 0;	//Unit minutes
	volatile int Light_Time_Up_Elapsed = 0;		//Unit minutes
	volatile boolean Light_Down = false;
	volatile boolean Light_Up = false;
/SETUP
        void setup(void)
		{
		//Define Fogger_Pin and Light_Pin as output
		pinMode(Fogger_Pin, OUTPUT);
		pinMode(Light_Pin, OUTPUT);
		//Define Time_Fogger_Down & Time_Fogger_Up
			//Read EEPROM Values 
			
		// Fogger_Time_Up_Elapsed = 5;
		// Fogger_Time_Down_Elapsed = 10;
		
		
		
		
		//--------------------------------------------------------Timer Interrupt-------------------------------------------------
		// initialize Timer1
		cli();          // disable global interrupts
		TCCR1A = 0;     // set entire TCCR1A register to 0
		TCCR1B = 0;     // same for TCCR1B
	 
		// set compare match register to desired timer count:
		OCR1A = 15624;
		// turn on CTC mode:
		TCCR1B |= (1 << WGM12);
		// Set CS10 and CS12 bits for 1024 prescaler:
		TCCR1B |= (1 << CS10);
		TCCR1B |= (1 << CS12);
		// enable timer compare interrupt:
		TIMSK1 |= (1 << OCIE1A);
		// enable global interrupts:
		sei();
		//-------------------------------------------------------------------------------------------------------------------------

		
		//Arduino serial begin
		Serial.begin(Arduino_Serial_Speed);
		
		Serial.print("Arduino Serial Port Speed,");
        Serial.println(Arduino_Serial_Speed);
          
		  
		//Xport Direct+ serial begin
		XPORT_Serial.begin(Xport_Serial_Speed);
		Serial.print("Xport Direct + Serial Port Speed,");
        Serial.println(Xport_Serial_Speed);
                
		//Initiate I2C bus
		Wire.begin();
		Serial.println("I2C Initialized");
		
		//Turn ON HIH610
		pinMode(HIH_POWER_Pin,OUTPUT);
		digitalWrite(HIH_POWER_Pin,HIGH);
		Serial.println("HIH6130 ON");
		
		//Config DS1621
		DS1621_Configuration(DS1621, DS1621_A2_A1_A0);
		Serial.println("DS1621 Configured");
		
		//Call Xport Reset
		xportReset();

			
		}

//LOOP
	void loop(void)
		{
		
		//Redefine Time_Down & Time_Up in seconds
		Fogger_Time_Up_Elapsed = 5;
		Fogger_Time_Down_Elapsed = 10;
		//Redefine Time_Down & Time_Up in seconds
		Light_Time_Up_Elapsed = 15;
		Light_Time_Down_Elapsed = 15;	
	
		
  		//Call DS18B20 function which return True or False
		float DS18B20_Temp;
		if(get_DS18B20_value(&DS18B20_Temp))
			{
			DS18B20_Temp = DS18B20_Temp;
			}
		else
			{
			//Write last know value
			DS18B20_Temp = DS18B20_Temp;
			}
		
		//Call DHT function which return True or False
		float DHT_Hum, DHT_Temp;
		if(get_DHT_values(&DHT_Hum,&DHT_Temp))
			{
			DHT_Hum = DHT_Hum;
			DHT_Temp = DHT_Temp;
			}
		else
			{
			DHT_Hum = 0;
			DHT_Temp = 0;
			}
			
		//Call HIH function which return True or False
		float HIH_Hum, HIH_Temp;
		if(get_HIH_values(&HIH_Hum,&HIH_Temp))
			{
			HIH_Hum = HIH_Hum;
			HIH_Temp = HIH_Temp;
			}
		else
			{
			HIH_Hum = 0;
			HIH_Temp = 0;
			}
		
		//Call DS1621 function which return True or False
		float DS1621_Temp;
		if(get_DS1621_value(&DS1621_Temp))
			{
			DS1621_Temp=DS1621_Temp;
			}
		else
			{
			DS1621_Temp = 0;
			}
			
		//Call LDR function which return the value
		int LDR_Value = get_LDR_Value();
	
		//Call xportConnect
		xportConnect();
		
		//Call httpRequest
		httpRequest(DS18B20_Temp, DHT_Hum, DHT_Temp, HIH_Hum, HIH_Temp, DS1621_Temp,LDR_Value);
		
		//Waiting for data
		WaitingForData();
		
		}
		
		
	//Traitement des interruptions
	ISR(TIMER1_COMPA_vect)
		{
			//Incrémentation de second
			second++;
			sec_for_min++;
			
			if(sec_for_min == 60)
				{
				minute = minute++;
				sec_for_min = 0;
				}
				
			//Test la valeur du booléen Fogger_Dow & Fogger_Up
			if (!Fogger_Down && !Fogger_Up)
				{
				Fogger_Down = true;
				}
			//Test la valeur du booléen Light_Dow & Light_Up
			if (!Light_Down && !Light_Up)
				{
				Light_Down = true;
				}
				
			
			//Toogle fogger if time elapsed
			if (!Fogger_Down && Fogger_Up)
				{
				if (second == Fogger_Time_Up_Elapsed)
					{
					digitalWrite(Fogger_Pin, LOW);
					second = 0;
					Fogger_Down = true;
					Fogger_Up = false;
					}
				}
			else if (Fogger_Down && !Fogger_Up)
				{
				if (second == Fogger_Time_Down_Elapsed)
					{			
					digitalWrite(Fogger_Pin, HIGH);
					second = 0;
					Fogger_Down = false;
					Fogger_Up = true;
					}
				}
				
			//Toogle light if time elapsed
			if (!Light_Down && Light_Up)
				{
				if (minute == Light_Time_Up_Elapsed)
					{
					digitalWrite(Light_Pin, LOW);
					minute = 0;
					Light_Down = true;
					Light_Up = false;
					}
				}
			else if (Light_Down && !Light_Up)
				{
				if (minute == Light_Time_Down_Elapsed)
					{			
					digitalWrite(Light_Pin, HIGH);
					minute = 0;
					Light_Down = false;
					Light_Up = true;
					}
				}
				
		}
		
//Reset the Xport Direct+
	void xportReset()
		{
		  pinMode(XPORT_RESETPIN, OUTPUT);
		  digitalWrite(XPORT_RESETPIN, LOW);
		  delay(100);
		  digitalWrite(XPORT_RESETPIN, HIGH);
		  delay(3000);
		  
		  Serial.println("Xport Direct+ reseted");
		}

//Connection to the IP and Port
	void xportConnect()
		{
		  byte theByte = 0;

		  while (theByte != 'C')
		  {
			XPORT_Serial.print(IP_AND_PORT);
			while(!XPORT_Serial.available()) {} // Just loop until available
			theByte = XPORT_Serial.read();
			Serial.println((char)theByte);
		  }
		  
		Serial.println("Xport Connected");
		}

	void httpRequest(float DS18B20_Temp, float DHT_Hum, float DHT_Temp, float HIH_Hum, float HIH_Temp, float DS1621_Temp, int LDR_Value)
	//	GET /Temperatures/xPortTest.php?value0=1&value1=2&value2=3&value3=4&value4=5&value5=6 HTTP/1.1
	//	Host: www.localhost
		{
		char temp[10];

		String DS18B20_Temp_Str;
		String DHT_Hum_Str;
		String DHT_Temp_Str;
		String HIH_Hum_Str;
		String HIH_Temp_Str;
		String DS1621_Temp_Str;
		
		
		//dtostrf(value, width, precision, output);
		/*where value is the float value you wish to convert,
		width is the minimum number of characters to display before the decimal point (padding with spaces as needed),
		precision is the number of decimal places, and output is the character array to put the results in.*/
		
		dtostrf(DS18B20_Temp,2,1,temp);
		DS18B20_Temp_Str = String(temp);
		
		dtostrf(DHT_Hum,2,0,temp);
		DHT_Hum_Str = String(temp);
		
		dtostrf(DHT_Temp,2,0,temp);
		DHT_Temp_Str = String(temp);
		
		dtostrf(HIH_Hum,2,5,temp);
		HIH_Hum_Str = String(temp);
		
		dtostrf(HIH_Temp,2,5,temp);
		HIH_Temp_Str = String(temp);
		
		dtostrf(DS1621_Temp,2,2,temp);
		DS1621_Temp_Str = String(temp);
		
		String LDR_Value_Str =  String(LDR_Value, DEC); 
		

		String str1 = "GET ";
		String str2 = "/Temperatures/xPortTest.php";
		String str3 = "?value0=";
		String str3b = DS18B20_Temp_Str;
		String str4 = "&value1=";
		String str4b = DHT_Hum_Str;
		String str5 = "&value2=";
		String str5b = DHT_Temp_Str;
		String str6 = "&value3=";
		String str6b = HIH_Hum_Str;
		String str7 = "&value4=";
		String str7b = HIH_Temp_Str;
		String str8 = "&value5=";
		String str8b = DS1621_Temp_Str;
		String str9 = "&value6=";
		String str9b = LDR_Value_Str;
		String str10 = " HTTP/1.1";
		
		String CommandLigne = str1 + str2 + str3 + str3b + str4 + str4b + str5 + str5b + str6 + str6b + str7 + str7b + str8 + str8b + str9 + str9b + str10;

		XPORT_Serial.println(CommandLigne);
		XPORT_Serial.println("Host: www.localhost");
		XPORT_Serial.println("Connection: Close");
		XPORT_Serial.println();
		}
	void WaitingForData()
		{
		byte theByte;
		String theString = "";
		char character;
		int InterrogationPosition = 0;
		//Wait for answer Ex:
							/*
							HTTP/1.1 200 OK
							Date: Mon, 06 May 2013 12:48:45 GMT
							Server: Apache/2.2.22 (Win32) PHP/5.4.3
							X-Powered-By: PHP/5.4.3
							Content-Length: 1
							Connection: close
							Content-Type: text/html
							*/
		while(!XPORT_Serial.available()) {} // Just loop until available
		
		while (XPORT_Serial.available())
			{	
			character = XPORT_Serial.read();
			theString += character;
			}
		Serial.println(theString);
		InterrogationPosition = theString.indexOf('?');
		//Test http answer
		if (theString.startsWith("200 OK", 9))
			{
			Serial.println("Got an OK from the server"); 
			}
		//test xmlhttprequest GET, si la position du '?' est supèrieure à 0
		else if (InterrogationPosition != 0)
			{
			//Envoi d'une réponse
			//XPORT_Serial.print(HTTP_HEADER);
			Serial.println("Got a command");
			}
		else
			{
			Serial.println("No OK from server"); 
			xportReset();
			}

		
		
		//Count the number of char in the answer
		// int CharCounter = 0;
		// while (XPORT_Serial.available())
			// {
			// CharCounter ++;
			// theByte = XPORT_Serial.read();
			// Serial.print((char)theByte);
			// }
        // Serial.println();
		// Serial.println(CharCounter);
		
		////If the number is not between to value then reset Xport.
		// if(CharCounter < 201 || CharCounter > 203)
		  // {
		  // xportReset();
		  // }
		
		}
		
//Read DS18B20 temperature value
	boolean get_DS18B20_value(float *DS18B20_Temp)
		{
		//Data from DS18B20 memory "Scratchpad", see Datasheet Figure 7. "DS18B20 Memory Map"
		byte scratchpad[9];
		//Address from 1-Wire detected sensor
		byte address[8];
		
		//Search for 1-Wire sensor
		//The address is an 8 byte array.
		//If a device is found, address is filled with the device's address and true is returned.
		//If no more devices are found, false is returned.
		if (!DS18B20_Sensor.search(address))	
			{
			//Begin a new search. The next use of search will begin at the first device.
			DS18B20_Sensor.reset_search();
			return false;
			}
		//Compute a CRC check on an array of data.
		else if (DS18B20_Sensor.crc8(address,7) !=address[7])
			{
			return false;
			}
		else if (address[0] != DS18B20)
			{
			return false;
			}
		else
			{
			//See page 8 of the datasheet : CONFIGURATION REGISTER
			//								Byte 4 of the scratchpad memory contains the configuration register, which is organized as illustrated in 
			//								Figure 8. The user can set the conversion resolution of the DS18B20 using the R0 and R1 bits in this 
			//								register as shown in Table 2. The power-up default of these bits is R0 = 1 and R1 = 1 (12-bit resolution). 
			//								Note that there is a direct tradeoff between resolution and conversion time. Bit 7 and bits 0 to 4 in the 
			//								configuration register are reserved for internal use by the device and cannot be overwritten.
			//See page 18 of the datasheet : "DS18B20 OPERATION EXAMPLE 1"
			//Reset the 1-wire bus.
			//Usually this is needed before communicating with any device.
			DS18B20_Sensor.reset();
			//Select a device based on its address.
			//After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
			DS18B20_Sensor.select(address);
			//Write a byte, and leave power applied to the 1 wire bus.
			DS18B20_Sensor.write(DS18B20_Convert_T,1);		//CONVERT T [44h] : This command initiates a single temperature conversion.
															//Following the conversion, the resulting thermal data is stored in the 2-byte temperature register
															//in the scratchpad memory and the DS18B20 returns to its low-power idle state.
			//Wait for 1000ms
			delay(800);		//The power-up default of these bits is R0 = 1 and R1 = 1 (12-bit resolution). So according with Table 2. Thermometer Resolution Configuration
							//MAX CONVERSION TIME = 750ms
			//Reset the 1-wire bus.
			//Usually this is needed before communicating with any device.
			DS18B20_Sensor.reset();
			//Select a device based on its address.
			//After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.
			DS18B20_Sensor.select(address);
			//Write a byte.
			DS18B20_Sensor.write(DS18B20_READ_SCRATCHPAD);		//READ SCRATCHPAD [BEh] : This command allows the master to read the contents of the scratchpad. The data transfer starts with the 
																//least significant bit of byte 0 and continues through the scratchpad until the 9th byte (byte 8 – CRC) is 
																//read. The master may issue a reset to terminate reading at any time if only part of the scratchpad data is needed.
			//Reading of DS18B20 memory "Scratchpad"
			for (byte i=0;i<9;i++)
				{
				scratchpad[i]=DS18B20_Sensor.read();	//Read a byte.
				}
			//Compute temperture in °C
			*DS18B20_Temp=((scratchpad[1] << 8) | scratchpad[0])*0.0625; // (MSB left offset 8 OR LSB) multiply by 0.0625
			//
			return true;
			}
		}
		
//Read DHT humidity and temperature value
	boolean get_DHT_values(float *DHT_Hum, float *DHT_Temp)
		{
		float temp=DHT_Sensor.readHumidity();
		float hum=DHT_Sensor.readTemperature();
		if (isnan (temp) || isnan(hum))
			{
			return false;
			}
		else
			{
			*DHT_Hum=temp;
			*DHT_Temp=hum;
			return true;
			}
		}

//Read HIH humidity and temperature value
	boolean get_HIH_values(float *HIH_Hum, float *HIH_Temp)
		{
		//Variables
		byte _status;	//To strore the value of the bits S1 and S0 of the first byte receive *** See Datasheet Figure 4. Humidity and Temperature Data Fetch, Four Byte Data Read
						//and Table 1. Diagnostic Conditions Indicated by Status Bits
		unsigned int Raw_Hum, Raw_Temp;	//To store the raw data 14 bits value
		float Convert_Hum, Convert_Temp;	//To store data after conversion of raw data
		
		//Compute status and raw data
		_status = fetch_humidity_temperature(&Raw_Hum, &Raw_Temp);
		
		//Read status value and set boolean to false or true
		switch(_status)
			{
			case(0):			//Normal Operation, Valid Data that has not been fetched since the last measurement cycle
				Convert_Hum = (float) Raw_Hum * 0.0061043;		//See datasheet 4.0
				*HIH_Hum = Convert_Hum;
				Convert_Temp = (float) Raw_Temp * 0.010072 - 40;	//See datasheet 5.0
				*HIH_Temp = Convert_Temp;
				return true;
				break;
			case(1):			//Stale Data: Data that has already been fetched since the last measurement cycle, or data fetched before the first measurement has been completed.
				return false;
				break;
			case(2):
				return false;	//Device in Command Mode
				break;
			default:			//
				return false;
				break;
			}
		}
//Compute HIH status and Humidity/Temperature raw data
	byte fetch_humidity_temperature(unsigned int *p_Raw_Hum, unsigned int *p_Raw_Temp)
		{
		//Variables
		byte address, Data_Byte_1, Data_Byte_2, Data_Byte_3, Data_Byte_4, status;
		unsigned int Raw_Hum, Raw_Temp;
		
		address=HIH6130;	//Address define up
		
		//Start a new transmission to a device at "address". Master mode is used.
		Wire.beginTransmission(address);
		//In master mode, this ends the transmission and causes all buffered data to be sent.
		Wire.endTransmission();
		delay(100);
		//Read "count" bytes from a device at "address". Master mode is used.
		Wire.requestFrom((int)address,(int)4);
		//Reads a byte that was transmitted from a slave device to a master after a call to requestFrom()
		//or was transmitted from a master to a slave. read() inherits from the Stream utility class.
		Data_Byte_1 = Wire.read();	//B13 to B8 of the Data Byte 1 *** See Datasheet Figure 4. Humidity and Temperature Data Fetch
		Data_Byte_2 = Wire.read();	//B7 to B0 of the Data Byte 2 *** See Datasheet Figure 4. Humidity and Temperature Data Fetch
		Data_Byte_3 = Wire.read();	//T13 to T6 of the Data Byte 3 *** See Datasheet Figure 4. Humidity and Temperature Data Fetch
		Data_Byte_4 = Wire.read();	//T5 to T0 + 00 of the Data Byte 4 *** See Datasheet Figure 4. Humidity and Temperature Data Fetch <> 00 is for the XX 
		//In master mode, this ends the transmission and causes all buffered data to be sent.
		Wire.endTransmission();
		
		//Decode Data_Byte_1 to extract S1 and SO and check the status
		status=(Data_Byte_1 >> 6) & 0x03;	//This means :
											//			1.Right shift Data_Byte_1 of 6	Ex:	1011 1111 >> 6 => 0000 0010
											//			2.AND 0x03						0000 0010 & 0000 0011 => 0000 0010  *** to check the shift result
		//Decode Data_Byte_1 to extract B13 to B8
		Data_Byte_1=Data_Byte_1 & 0x3f;		//To erase S1 and S0 from Data_Byte_1 Ex: 1011 1111 & 0x3f => 1011 1111 & 0011 1111 => 0011 1111
		//Store Data_Byte_1 and Data_Byte_2 in 2 bytes value
		Raw_Hum=(((unsigned int)Data_Byte_1) << 8) | Data_Byte_2;	// Put Data_Byte_1 in a 2 byte value, left shift of 8 and OR with Data_Byte_2
																	//Ex: 0011 1111 => 0000 0000 0011 1111 << 8 => 0011 1111 0000 0000 OR 1111 1111 => 0011 1111 1111 1111
		//Store Data_Byte_3 and Data_Byte_4 in 2 bytes value
		Raw_Temp=(((unsigned int)Data_Byte_3) << 8) | Data_Byte_4;	// Put Data_Byte_3 in a 2 byte value, left shift of 8 and OR with Data_Byte_4
																	//Ex: 1111 1111 => 0000 0000 1111 1111 << 8 => 1111 1111 0000 0000 OR 1111 1100 => 1111 1111 1111 1100
		//But Raw_Temp is a 16 bits value and we want a 14 bits value so we divide by four
		Raw_Temp=Raw_Temp/4;	//Ex: 1111 1111 1111 1100 = dec(65532) and dec(65532)/4 = dec(16383) = 0011 1111 1111 1111
		
		*p_Raw_Hum = Raw_Hum;
		*p_Raw_Temp = Raw_Temp;
		
		return(status);
		}

//Configuration of DS1621
	boolean DS1621_Configuration(byte Generic_Address, byte Pin_Config)
		{
		byte address;
		address = get_DS1621_Address(Generic_Address, Pin_Config);
		
		//Send of Stop Convert
		Wire.beginTransmission(address);
		Wire.write(DS1621_Stop_Convert_T);
		Wire.endTransmission();
		
		//To use the low-power idle state, we will use the configuration register and set the Lsb to 1
		Wire.beginTransmission(address);
		Wire.write(DS1621_Access_Config);
		Wire.write(DS1621_Config_Reg);
		Wire.endTransmission();
		delay(100);
		return true;
		}
		
//Read DS1621 temperature value
	boolean get_DS1621_value(float *DS1621_Temp)
		{
		//Variables
		byte address;
		address = get_DS1621_Address(DS1621, DS1621_A2_A1_A0);
		
		byte Data_Byte_1, Data_Byte_2, Counter, Slope, Register_Value;
		int Counter_Int, Slope_Int, Raw_Temp, Temp;
		
		
		//Send of Start Convert
		Wire.beginTransmission(address);
		Wire.write(DS1621_Start_Convert_T);
		Wire.endTransmission();

		//Loop until Register MSb = 1 so while Register_Value < 10000000 ou 0x80
		while (Register_Value < 0x80)
			{
			Register_Value = get_DS1621_Register_value(address);
			}
		
		//Send Read Temp Command
		Wire.beginTransmission(address);
		Wire.write(DS1621_Read_Temperature);
		Wire.endTransmission();
		Wire.requestFrom((int)address,(int)2);
		Data_Byte_1 = Wire.read();
		Data_Byte_2 = Wire.read();
		
		//Send Read Counter Command
		Wire.beginTransmission(address);
		Wire.write(DS1621_Read_Counter);
		Wire.endTransmission();
		Wire.requestFrom((int)address,(int)1);
		Counter = Wire.read();
		
		//Send Read Slope Command
		Wire.beginTransmission(address);
		Wire.write(DS1621_Read_Slope);
		Wire.endTransmission();
		Wire.requestFrom((int)address,(int)1);
		Slope = Wire.read();
		
		//Send of Stop Convert
		Wire.beginTransmission(address);
		Wire.write(DS1621_Stop_Convert_T);
		Wire.endTransmission();
		
		//Compute high precision temperature from Data_Byte_1, Counter and Slope
		//Does the value is positive or negative ?
		if (Data_Byte_1 < 0x80)
			{
			Raw_Temp = int(Data_Byte_1);
			}
		else
			{
			Data_Byte_1= Data_Byte_1 | 0xFE;
			Raw_Temp = int( Data_Byte_1);
			Raw_Temp = Raw_Temp * (-1);
			}
			
		Temp = Raw_Temp *100 - 25 + (100 * (Slope - Counter) / Slope);
		*DS1621_Temp = (float( Temp) / 100);
		
		}
		
//Read the MSb of the register of the DS1621
	byte get_DS1621_Register_value(byte address)
		{	
		Wire.beginTransmission(address);
		Wire.write(DS1621_Access_Config); 
		Wire.endTransmission();
		Wire.requestFrom(int(address), int(1));
		byte Register_Value = Wire.read();
		return Register_Value;
		}

//Compute DS1621 address
	byte get_DS1621_Address(byte Generic_Address, byte Pin_Config)
		{
		byte address;
		//Compute the real address with last bit to 0 (Write)
		address = Generic_Address | Pin_Config;
		//The Wire library wants just the upper seven bits *** See : http://arduino.cc/forum/index.php?PHPSESSID=de9b62bcfa573e373cc37b7f689ba386&topic=2162.15
		//The LSb is automatically write by <wire.h> library
		//So:
		address = address >> 1;
		return address;
		}
		
//Compute LDR Illumination value
	int get_LDR_Value()
		{
		int LDRReading = analogRead(LDR_Pin);
		return LDRReading;
		}

Pourquoi je veux tout avoir alors que la partie de code suivante fait bien le job c.a.d trouver un “200”:

if (theString.startsWith("200 OK", 9))
			{
			Serial.println("Got an OK from the server"); 
			}

En fait mon serveur me génère une page html avec entre autres un bouton (ce sera deux groupes de deux sliders par la suite) qui vont me permettre de faire varier les valeurs de Light_Time_Up_Elapsed, Light_Time_Down_Elapsed, Fogger_Time_Up_Elapsed & Fogger_Time_Down_Elapsed dans ISR(TIMER1_COMPA_vect) tout en enregistrant dans une table ces commandes, leurs valeurs, l’heure et la date.

Code html + JS, utilisant de XMLHttprequest:

<p align="center">
			<input type="button" name="ESSAI" id="ESSAI" onclick="TryToSendDataToArduino()" />
		</p>

			<script type="text/javascript">
				function showValue(newValue)
					{
					   document.getElementById("range").innerHTML=newValue;
					}
				function TryToSendDataToArduino()
					{
					var xhr_object = null; 

					if(window.XMLHttpRequest) // Firefox 
						xhr_object = new XMLHttpRequest(); 
					else if(window.ActiveXObject) // Internet Explorer 
						xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
					else { // XMLHttpRequest non supporté par le navigateur 
						alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
						return; 
						} 
 
					//xhr_object.open("GET", "couic.txt", true); 
					xhr_object.open("GET", "http://192.168.1.50:10001?C=" + 1 + "&ON=" + 10 + "&OFF=" + 5, false); 

					xhr_object.onreadystatechange = function() { 
						if(xhr_object.readyState == 4) alert(xhr_object.getAllResponseHeaders()); 
						} 
	 
					xhr_object.send(null); 

					xhr_object.abort();
					}
			</script>

Cette requête GET vers l’adresse du Xport Direct+ et le port 10001 porte les valeurs qui vont modifier les variables listées ci-dessus.

Et dans ce cas, il me faut travailler sur la requête au complet et je retombe sans doute dans le cas d’un SoftwareSerial Buffer Overflow !

Exemple de sortie via Serial du GET généré par XMLHttpRequest:

I192.168.1.15
GET /?C=1&ON=10&OFF=5 HTTP/1.1
Host: 192.168.1.50:10001
Connection: keep-alive
Origin: http://localhost
Use