Pages: [1]   Go Down
Author Topic: HTTP POST Request-Wifi Help  (Read 1032 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

This is my first post and I am new to arduino.  I am working on a class project where we are trying to setup a parking garage monitoring system.  I have attached two photoelectric sensors to my arduino board and I have them recognized in a sketch.  As one sensor is tripped it will display "car entered" and when the other is tripped it will display "car exit".   I am trying to send an HTTP Post request from my arduino (with a wifi shield) to a server where it is being entered into a database and eventually sent to a website that other groups in the class are setting up. 

Unfortunately I am relatively unexperienced in the programming world and I have no idea where to begin for this process.  I will include my sketch from the sensors but I need to be able to send a packet to the "database team".  The packet needs to include a Location ID(arbitrary name that I can make up), a count of cars (+1 for enter, -1 for exit), and a flag field (optional).  If someone could please help me out that would be greatly appreciated.  The location of the server is http://IP-Address-of-server/sensors/event.php

int sensorPin = A0; // select the input pin for the potentiometer
int sensorPin2 = A1;// input from second (exit) sensor
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
int sensorValue2=0;
int i = 0; //variable used to count

void setup() {
 // declare the ledPin as an OUTPUT:
 pinMode(ledPin, OUTPUT);
 Serial.begin(9600);
}

void loop() {
 // read the value from the sensor:
 sensorValue = analogRead(sensorPin);
 sensorValue2=analogRead(sensorPin2);
 //Serial.println(sensorValue);
 if(sensorValue < 150 && sensorValue > 141) { // value is less than 155 if sensor is detects something
 i=0;
   do {
     if(sensorValue > 155 || sensorValue < 140) {
       Serial.println("off");
       break;
     }
     delay(100);
     i++;
     if(i==10) {
       Serial.println("car entered");
       i=0;
       break;
   }
   }
 while(1);
 ////////////
}
if(sensorValue2 < 155 && sensorValue2 > 140) { // value is less than 175 if sensor is detects something
 i=0;
   do {
     if(sensorValue2>155) {
       Serial.println("off");
       break;
     }
     delay(200);
     i++;
     if(i==10) {
       Serial.println("car exited");
       i=0;
       break;
   }
   }
 while(1);
}

 // turn the ledPin on
 digitalWrite(ledPin, HIGH);
 // stop the program for <sensorValue> milliseconds:
 //delay(sensorValue);
 // turn the ledPin off:
 digitalWrite(ledPin, LOW);
 // stop the program for for <sensorValue> milliseconds:
 delay(sensorValue);
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am trying to send an HTTP Post request from my arduino (with a wifi shield) to a server
Not with that code you aren't. Maybe that is what you eventually want to do, but there is nothing there that acknowledges the existence of a WiFi shield.

Which WiFi shield do you have? What libraries came with it? What examples? There should be something you can modify to suit your specific needs.

Code:
if(sensorValue < 150 && sensorValue > 141) { // value is less than 155 if sensor is detects something
This would make more sense if the conditions were reversed.
Code:
if(sensorValue > 141 && sensorValue < 150)
{

Code:
do {
     if(sensorValue > 155 || sensorValue < 140) {
       Serial.println("off");
       break;
     }
     delay(100);
     i++;
     if(i==10) {
       Serial.println("car entered");
       i=0;
       break;
   }
   }
 while(1);
This needs some serious restructuring. Almost any time a do/while loop is used like this, it is a clear indication that the programmer doesn't know what he/she is doing. The sensorValue variable's contents can not change in the do/while loop, so it's initial value will determine when, or if, the loop ever ends, meaning that the loop will execute once or infinitely. This is almost certainly NOT what you want. The infinite part, at least.

Code:
// stop the program for for <sensorValue> milliseconds:
 delay(sensorValue);
While another car sneaks in undetected...
Logged

Pages: [1]   Go Up
Jump to: