1

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
  • 1
    Hi, thank you for spotting my mistake. I already update my arduino sketch. It almost took my breathe away, but I hate to say this. The issue persist.

    client.connect("the******tem.com", 80)){ client.println("POST /dataPost.php HTTP/1.1"); client.println("Host: the******tem.com"); client.println("Content-Type: application/x-www-form-urlencoded"); client.print("Content-Length: "); client.println(data.length()); client.println(); client.print(data); client.stop();

    already double check with http request format. Any idea about this?

    – Briant Stevanus Jul 29 '19 at 21:43
  • you have not said anything about any errors that you are or are not getting – jsotola Jul 30 '19 at 00:47
  • @jsotola Hi, thank you for highlight this. But I am really sorry, I didn't get any errors report. – Briant Stevanus Jul 30 '19 at 03:02
  • print the response – Juraj Jul 30 '19 at 04:42
  • 1
    hi @Juraj it is nice to meet you here. I read a lot your answers. You are such a big help for community. What kind of response do you need?

    It confuse me, since we still can see sensor value from serial monitor.

    I would like to update this issue, it may be because of server hosting fault. I can manage to store data via GET although I understand it is not the best practice.

    – Briant Stevanus Jul 30 '19 at 18:36
  • Thank you @Majenko :) – Briant Stevanus Jul 30 '19 at 18:36

0 Answers0