Hey everyone,
I am running into an issue that I have been trying to fix for the last 3 days.
I am using multiple ultrasonic (HC-SR04) sensors to check if a parking spot is taken, and checking for multiple levels of a parking garage. and then uploading the results to an API.
#include <Bridge.h>
#include <HttpClient.h>
#include <NewPing.h>
//row 1
NewPing sensor11(50, 50, 200);
NewPing sensor12(52, 52, 200);
NewPing sensor13(53, 53, 200);
//row 2
NewPing sensor21(45, 45, 200);
NewPing sensor22(46, 46, 200);
NewPing sensor23(47, 47, 200);
//row 3
NewPing sensor31(39, 39, 200);
NewPing sensor32(40, 40, 200);
NewPing sensor33(41, 41, 200);
//row 4
NewPing sensor41(31, 31, 200);
NewPing sensor42(32, 32, 200);
NewPing sensor43(33, 33, 200);
void setup() {
Bridge.begin();
}
void loop() {
// adding up the cars for row 1
int countOne = 0;
if (sensor11.ping()/US_ROUNDTRIP_CM < 15) countOne++;
delay(250);
if (sensor12.ping()/US_ROUNDTRIP_CM < 15) countOne++;
delay(250);
if (sensor13.ping()/US_ROUNDTRIP_CM < 15) countOne++;
delay(250);
String levelOne = String(countOne);
// adding up the cars for level 2
int countTwo = 0;
if (sensor21.ping()/US_ROUNDTRIP_CM < 15) countTwo++;
delay(250);
if (sensor22.ping()/US_ROUNDTRIP_CM < 15) countTwo++;
delay(250);
if (sensor23.ping()/US_ROUNDTRIP_CM < 15) countTwo++;
delay(250);
String levelTwo = String(countTwo);
// adding up the cars for level 3
int countThree = 0;
if (sensor31.ping()/US_ROUNDTRIP_CM < 15) countThree++;
delay(250);
if (sensor32.ping()/US_ROUNDTRIP_CM < 15) countThree++;
delay(250);
if (sensor33.ping()/US_ROUNDTRIP_CM < 15) countThree++;
delay(250);
String levelThree = String(countThree);
// adding up the cars for level 4
int countFour = 0;
if (sensor41.ping()/US_ROUNDTRIP_CM < 15) countFour++;
delay(250);
if (sensor42.ping()/US_ROUNDTRIP_CM < 15) countFour++;
delay(250);
if (sensor43.ping()/US_ROUNDTRIP_CM < 15) countFour++;
delay(250);
String levelFour = String(countFour);
HttpClient client;
client.get("http://example.com/api/test/" + levelOne + "" + levelTwo + "" + levelThree + "_" + levelFour );
}
the problem I am running into is the following:
no matter what distance the sensors pick up, the request to the server always ends up being "/api/test/3_3_3_3".