Hi friends!
I'm a newcomer about arduino or programme.
I use a Arduino UNO and enc28J60 program a HTTP POST method ,meeting a lot of problems.
first,I confused about library of enc28J60.
someone use a kind of method sending POST messages,some use another..
I just want samply receive the GET informations in order to control my LED status,
POST my sensors data to my web server.
And some litte problem confused me to death,like...
when I create a new funciton like
send_data2web(IN char *temp,IN char *hum)
{
char data2send1 = temp;
char data2send2 = hum;
String PostData="sample={\"fittingId\":1,";
unsigned char i;
for(i=1;i<3;i++)
{
PostData=PostData+"\"channel-";
PostData=String(PostData+i);
PostData=PostData+"\":";
PostData=String(PostData + String(data2send+i);
if(i!=2)
PostData=PostData+",";
}
PostData=PostData+"}";
if (client.connect(server, 80)) // I confused here about how initializing enc28J60 and sending POST messages.
{
Serial.println("\nconnected...");
Serial.println("ARDUINO: forming HTTP request message");
client.println("POST /UNIControl/PhpPost.php HTTP/1.1"); //setting PHP
client.println("From: Arduino_room1 ");
client.println("POST /tinyFittings/index.php HTTP/1.1");
client.println("Host: 192.168.2.42");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("User-Agent: HTTPTool/1.0");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print ("Content-Length:");
client.println(DatatoSend.length());
client.println("Connection: close");
client.println(DatatoSend);
client.println();
Serial.println("ARDUINO: HTTP message sent");
delay(3000);
if(client.available())
{
Serial.println("ARDUINO: HTTP message received");
Serial.println("ARDUINO: printing received headers and script response...\n");
while(client.available())
{
char c = client.read();
Serial.print(c);
}
}
else
{
Serial.println("ARDUINO: no response received / no response received in time");
}
client.stop();
}
else
{
Serial.println("connection failure");
}
delay(2000);
}
temp_hum(OUT char*temp,OUT char*hum)
{
int chk = DHT11.read(DHTPIN);
int Tc_100 =(float) DHT11.temperature*10;
int whole_temp, fract_temp;
whole_temp = Tc_100/10 ; // separate off the whole and fractional portions
fract_temp = Tc_100 % 10;
sprintf(temp,"{\"valueTemp\":%d.%d}",whole_temp,fract_temp); //setting temp value in char type like "valueTemp:tempValue"
int Tc_200 =(float) DHT11.humidity*10;
whole_temp = Tc_200/10 ; // separate off the whole and fractional portions
fract_temp = Tc_200 % 10;
sprintf(hum,"{\"valueHum\":%d.%d}",whole_hum,fract_hum); //setting hum value in char type like "valueHum:humValue"
}
}
running it in the
loop(){
temp_hum(temp,hum);
send_data2web(temp,hum);
}
it always coming out the tips the function "temp_hum" was not declared in this scope......
I wonder what's the correct writting when I created a function outside the loop() funtion and want it run in loop();
other big question is receive my Web server's status and control my LED
I wrote like this:
ledlight(OUT char *led) {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
Serial.println("Received ON command");
ledStatus = true;
}
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
Serial.println("Received OFF command");
ledStatus = false;
}
if(ledStatus) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
sprintf(led,"{\"valueLED\":%d}",ledStatus);
}
}
my questions are quit a lot,many thanks to your help