MAI and ESP8266 coupled to Arduino IDE

Hello everyone, first off I have been working with Arduino IDE in conjunction with the Wemos Mini D1 and the ESP8266 Dev Board. My hobby since retirement. This is not my area of expertise so I rate myself as a beginner.

I created a sketch for taking on the tasks of plant and lawn watering with ESP8266 controller
The front end is a crude text-based web page that I found and used from the web. It was a cut and paste no programming knowledge on my part.

What I would like to do is create a front end for my cell phone to control watering sketch mentioned above. Maybe override button for emergencies and calendar for when to water and clock for the time duration.

This is where MIT App Inventor comes into play, unfortunately, can not find clear step-by-step tutorials to guide me through the process.

Found one step by step tutorial but it was lacking and left out steps the author thought were obvious. I did manage to get it working but it posted an error and stopped working after about a minute. If I cut power to the ESP8266 Dev Bd it would work again but stop after a minute.

The author could not be reached so here I am.

I will link the example that failed if requested also will show code for my lawn sprinkler sketch if needed. Right now, what I need is learning how to use MAI. I have read and watched many tutorials both on the MIT site and around the web nothing so far.

If I left anything out please feel free to let me know.

Tried using this example for first try at using MAI.
https://iotdesignpro.com/projects/esp8266-iot-home-automation-using-mit-app-inventor

Post your sketch and your exported .aia file.
Downloaded Blocks Image would also speed things up.


Please export your project and post it here.

Thank you for your help. I Will post the sketch but will need help with the posting of .aia file.

#include <ESP8266WiFi.h>

const char* ssid = "removed ssid";
const char* password = "removed passwd";

WiFiServer server(80);

void setup() {
Serial.begin(115200); //Default Baud Rate for NodeMCU
delay(10);

pinMode(2, OUTPUT); //NodeMCU's D4 or GOIO2 Pin
digitalWrite(2, 0);

// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.println(WiFi.localIP());
}

void loop() {
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("new client");

while(!client.available()){
Serial.println("Client.available");
delay(1);
}

String req = client.readStringUntil('\r');
Serial.println(req);
client.flush();

int val;
if (req.indexOf("/gpio/0") != -1)
val = 0;
else if (req.indexOf("/gpio/1") != -1)
val = 1;
else {
Serial.println("invalid request");
client.stop();
return;
}

// Set GPIO2 according to the request
digitalWrite(2, val);

client.flush();

String s = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n\r\n\r\nGPIO is now ";
s += (val)?"high":"low";
s += "";
}

IotDesignProExple.aia (1.7 KB)

Here is the error that pops up on my cell phone after pressing either button it eventuall y fades but returns after pressing either of the two buttons.

ErrorOnCell

If you haven't seen it yet, see

Regarding your local setup, can you reach your ESP from the web viewer that came with your phone, using Wifi?

I currently following his lessons and have his book. I was able to use the app as outlined in my OP did not try opening using a browser on my cell phone. It did however work with my desktop PC browser without any errors.

Your PC can reach your ESP because it is on the same local network (192.168.etcetc).

You have not yet demonstrated that your phone can reach a local network address.

Check the settings on your phone.

Another thing to try ...
Use a WebViewer instead of a Web component.
They sign onto local routers better than Web components.

P.S. Your sketch uses \r (carriage return) in addition to \n (New Line).
CR is used in Windows but not in Unix-alikes like your phone.

UPDATE: tried using my cell phone and browser and was able to control the LED via that method.
OK I was able to run the example from my cell phone and watched the onboard leds turn on and off. Thought that qualified for connection between the cell phone and my wifi network which is where the ESP8266 is located.

In that case, go on to the WebViewer replacement and see if it can get through.

Sorry for the duplicate post but tried as you requested and was able to get the led to switch on/off using browser on my cell phone. Sorry what is "Web Viewer replacement"?

the last component in the User Interface drawer in the Designer.

Guessing using the web viewer will not be necessary test beings I got the browser via my cell phone to operate the sketch on/off features.