-2

it's been week that i am having issue,that i can’t get ultrasonic readings when i connect with my esp8266 wifi module ,everytime it gives 0 cm reading.My

both hardwares work perfectly if i connect them individually. i also divided a code of ultrasonic and esp8266 for the debugging steps,both are working. but when i combine both code together i get no response. In my database server i get 0 distance.

Note: using external power of 5v for ultrasonic sensor. Is there any logical problem? please help Sir thanks. Here is a code

#include<ESP8266WiFi.h>
#include<ESP8266HTTPClient.h>
#define trigger 12
# define echo 13
float timex = 0;
float distance = 0;
float max_height = 0;
float extra_space = 4.00;

int TANK_SPECIAL_ID = 1;

void setup() {
    pinMode(trigger, OUTPUT);
    pinMode(echo, INPUT);
    Serial.begin(115200);
    delay(5000);
    WiFi.begin("AndroidAP", "lovely12");

    Serial.println("Setup Initiated\ n");

    while (WiFi.status() != 3) {
        delay(500);
        Serial.println("Waiting for connection");
        Serial.print("WiFi Status: ");
        Serial.println(String(WiFi.status()));
    }
    Serial.println(String(WiFi.status()));
}

void loop() {
        HTTPClient http;
        int Percentage = 0;
        digitalWrite(trigger, LOW);
        delayMicroseconds(2);
        digitalWrite(trigger, HIGH);
        delayMicroseconds(10);
        digitalWrite(trigger, LOW);
        delayMicroseconds(2);
        timex = pulseIn(echo, HIGH);
        distance = timex * 340 / 20000;

        if (max_height == 0) {
            Serial.println("Setting max_height");
            max_height = distance;
            Serial.println("max_height configured..5 seconds delay");
            delay(5000);
            Percentage = -1;
            Serial.print("MAX HEIGHT: ");
            Serial.println(max_height);
        } else {
            int revVal = int(distance / max_height * 100);
            Percentage = revVal– 100;
            Serial.print("Current Ratings: ");
            Serial.print(distance);
            Serial.print(" cm");
            Serial.print(" | Percentage: ");
            Serial.print(Percentage);
            Serial.println(" %");

        }
        if (distance > -1) {
            String Data = "x=" + String(Percentage) + "&y=" + String(max_height) + "&z=" + String(TANK_SPECIAL_ID);
            http.begin("http://zaptraff.atwebpages.com/IOT/IOTCON.php");
            http.addHeader("application/x-www-form-urlencoded");

            int sent = http.POST(Data);
            Serial.print("Request val: ");
            Serial.println(sent);
            //String httpPayload = http.getString();
            //Serial.println(httpPayload);
            if (sent > 0) {
                Serial.println("Data has been sent");
            } else {
                Serial.println("unable to send data");
            }
        }
        delay(1000);
    }
}
  • hello????????????? – Alam Rockx Jan 4 '18 at 19:31
  • Tell us what happens (exactly) and what doesn't happen, and perhaps you'll get more interest. – Mark Smith Jan 4 '18 at 19:37
  • i put my all interest to sort out that problem, the exact problem is that my sensor is not giving the distance reading.. when i try to upload that values to my server with ESP8266 – Alam Rockx Jan 4 '18 at 19:48
  • i put my all interest to sort out that problem, the exact problem is that my sensor is not giving the distance reading.. when i try to upload that values to my server with ESP8266 – Alam Rockx Jan 4 '18 at 19:48
  • seems like nobody is intrested to solve my problem although i explained each and everything in post :/ – Alam Rockx Jan 4 '18 at 19:59
0

As the MIME type implies application/x-www-form-urlencoded is URL encoded. Non-alphanumeric characters must be percent encoded.

It looks like this line:

if (distance > -1) {

Should be:

if (Percentage > -1) {

Further:

Percentage = revVal– 100;

Is sometimes negative. So String(Percentage) is producing - which is likely tripping up your web server because this is an illegal character when parsing x-www-form-urlencoded.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.