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.

11
  • 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 :) 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
  • 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? Jul 29 '19 at 21:43
  • 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. Jul 30 '19 at 18:36

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.