0

I am creating a slot sensor, using photoresistor. The goal is to send the photoresistor value, via analog read, pin A0 to my web server, so I can stored it in my database.

void loop() { int sensorvalue = analogRead(A0);// LightValue, read from sensor pin A0 data = "sensorValue=" + (sensorvalue); //there is a car parked if(sensorvalue >=1000){ if(flagstatus == false){ if (client.connect(server, 80)){ Serial.println("Connected to Host Server"); client.println("POST /dataPost.php/HTTP/1.1"); client.print("Host:"); client.println(server); client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(data.length()); client.println(); client.print(data);

I've been trying to send mock data via postman, and it works like a charm, so I can eliminate my server side from the equation. Been guessing using : or = on sensorvalue=analogread(a0) or sensorvalue:analogread(a0). Or I made mistake on the code? I don't know much in Arduino, and this issue kinda frustrate me.

arduinosetup

the Image just for confirmation only, of course I installed the protoboard correctly.

Connect to SSID: Adamar IP Address: 192.168.1.14 Connect to server... Connected with network--------- Connected to Host Server sensorvalue:1007 There is still a car parked sensorvalue:1007 There is still a car parked sensorvalue:1008 I manage to get this result from my serial monitor, so I think there is no wrong reading from my setup.

  • Before you start writing software that generates HTTP requests, you really should learn the format of an HTTP request. – Majenko Jul 29 '19 at 19:39
  • hi, thank you for your friendly reminder :) Any suggestion? been go back and forth around this topic without any clear answer. About format, all snippets code, and example code from arduino written that way :) – Briant Stevanus Jul 29 '19 at 19:46
  • You might want to look at the line "POST /dataPost.php/HTTP/1.1" – Majenko Jul 29 '19 at 19:47
  • thank you for the hint on POST /dataPost.php/HTTP/1.1 , could you please be more elaborate? – Briant Stevanus Jul 29 '19 at 19:57
  • The correct format is POST /dataPost.php HTTP/1.1 – Majenko Jul 29 '19 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.