Displaying data from IR sensor into MIT App by using WiFi connection

Hello, I'm having a problem in displaying data received from IR Sensor into MIT App using WiFi connection. I'm planning to create a simple app that displays the status of a parking slot whether it is occupied or vacant on MIT app. When the IR Sensor detects a car, the status will turn Red (Not Available) whereas when the IR Sensor detects nothing, the status will turn Green (Available).

I really have no idea how to do it since this can be achieved normally using Bluetooth. I've attached the blocks that I've made so far which I believe have a lot of mistakes. Can someone help me? Thanks in advance.

Capture

What is the IP address of the sensor?

What do you see in your web browser if you go to that IP address?

It's 192.168.0.100 and there's only blank page

How do you know about the IP address and the expected responses?

Are you trying to reach that IP address through a WiFi connection, or through your cell phone
service?

is a local network address, only reachable locally.

It's through Wifi connection. Truth is I only have the code for Wifi connection + the IR sensor on Arduino IDE and I haven't done the MIT App code blocks part completely because I have no idea how to start on it.

You haven't shown any hope that the Arduino code is responding to web requests.
Post the code for our Arduino experts?

I'm sorry, here's the Arduino code, sir.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#define IR D6       // connect ir sensor to nodemcu pin D5
#define RedLED 14      // connect LED to nodemcu pin D3
#define GreenLED 2    // connect LED to nodemcu pin D7

String page = "";
bool data; 

int slot1;    // Parking slot 1


String  command;

const char* ssid = "TP-LINK_M5_D79F4C";  // WiFi Name
const char* password = "10250712";       // WiFi Password

ESP8266WebServer server(80);

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Declaration of LCD

void setup() {

  Serial.begin(9600);

  pinMode(IR, INPUT);         // Sensor pin INPUT
  pinMode(RedLED, OUTPUT);     // LED pin OUTPUT
  pinMode(GreenLED, OUTPUT);    // LED pin OUTPUT


  //Start WiFi connection

  WiFi.disconnect();
  delay(2000);
  Serial.println();
  Serial.print("Wifi connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  Serial.println();
  Serial.print("Connecting");
  
  while( WiFi.status() != WL_CONNECTED )
  {
  delay(500);
  Serial.print(".");        
  }
  
  Serial.println();
  Serial.println("Wifi Connected!");
  Serial.print("NodeMCU IP Address: ");
  Serial.println(WiFi.localIP() );

 // Starting WEB-server 
  server.on ( "/", HTTP_handleRoot );
  server.onNotFound ( HTTP_handleRoot );
  server.begin();
  

 // Start displaying on LCD
  lcd.begin(16, 2);             // LCD 16 columns and 2 rows
  lcd.print("Smart Parking");   // Print on first row of LCD
  delay(10);
  lcd.setCursor(0, 1);          // Move the cursor to the next line and print
  lcd.print("System");
  delay(1000);
  lcd.clear();
  Serial.println("Starting Project......");
  Serial.println();
}


void loop() {

  slot1 = digitalRead (IR);
  delay(500);

  //read the sensor and light up the LED
  //vacant(green), occupied(red)

  server.handleClient();
  command = server.arg("State");

 if (slot1 == 1) {   
  digitalWrite(RedLED, HIGH);
  digitalWrite(GreenLED, LOW);
  lcd.setCursor(1, 0);            // Move the cursor to the next line and print
  lcd.print("Slot 1: 0");
  delay(500);
 }

 
else   
 {
   digitalWrite(GreenLED, HIGH);
   digitalWrite(RedLED, LOW);        // LED LOW
   lcd.setCursor(1, 0);   
   lcd.print("Slot 1: 1");
delay(100);
  }

}

void HTTP_handleRoot(void) 
{
  page = "<h1>Sensor to Node MCU Web Server</h1><h3>Data:</h3> <h4>"+String(data)+"</h4>";
  server.send ( 200, "text/html", page );
  delay(1);
}
1 Like

I am seeing some holes in your Arduino code ...

Your Http code is:

void HTTP_handleRoot(void) 
{
  page = "<h1>Sensor to Node MCU Web Server</h1><h3>Data:</h3> <h4>"+String(data)+"</h4>";
  server.send ( 200, "text/html", page );
  delay(1);
}

but You did not see the response Sensor to Node MCU Web Server in a web browser?
That points to a setup problem in your Arduino code. (look for samples on this board.)

You send String(data) as your web response but you never modify the variable data from its boolean initialization value.

I advise getting decent web browser responses before trying to go further with AI2.

Displaying data from IR sensor into MIT App by using Bluetooth connection and design application fast please

OMG. I realized now that the post was dated 2020 !!! Please apologise me if I have spammed the forum. !!!

You can refer to this old topic, where I've annexed (answert #13 more or less) both 8266 and MIt codes with their explanation.

Starting from there you can adapt these chunks of code for your needs (I guess :grin:).
Best wishes.