Help with sending command to esp8266-01 module

I installed a wifi socket widget app from playstor which controls arduino using esp8266-01 module by sending a command "IP address: port/command" and it works good but I want to create an app in MIT app inventor to control this project I tried an approach but failed!

First see widget which works good:

f0834ad0297fce1c3b6a710a823e866ed77cf61d_2_1380x868|690x434
What format should I use to send this command.

The second post is also mine and this was for Bluetooth not for WiFi!!!!

I went through the first post discussions but first of all my problem need to be understood first then anyone can direct me to extensions right. I send commands to other arduino codes they work but the code which I am trying wants \n to receive first then FA to work. Here I am unable to judge how to send " \n "and " FA "........!...?

AI2 apps typically connect thru the Web or WebViewer components, through the URL.

Special characters like \n can be sent encoded, by text JOIN:
Capture

1 Like


I want to change this blocks code to send some command. My esp ip is 192.168.4.1 and port is 80.
I send command with wifi serial terminal app from play store works good, also when i use Socket Widget App whose screenshot is above, it still works good but when i try send the same command with this app ,wifi just receives commands but not works. I am not ablle to find the exact block that can send the command so that my arduino led works through esp8266 module

Help From Anyone Would Be Appreciated..... :slight_smile:

I don't know why you dragged tinyDB into this.
Anyway, here is one way to do this ...

webview_esp8266_sample.aia (2.3 KB)

The Do It screen shot is from a first shot, before I moved all the \n and \r outside the button text.

Than you for your reply.......
When I click the buttons it opens a web page while as my target is to send commands to esp module offline to make LEDs on arduino on or off. In arduino I check the data on esp and when the proper condition is met LEDs are powered on or off on arduino pins.
The widget app sends this command to perform the same operation see this widget configuration page:

See how its icons look at my phone screen. It needs an additional icon to configure for each command that is why I hate this widget app and I want to make my own app.:


First image : 192.168.4.1:80/FA make arduino led ON if it was off.
Second image : The icons white named as OFF and ON are icons of this widget app.
For OFF button the command is 192.168.4.1:80/FX which makes led OFF.
IMPORTANT NOTE::: Like we send commands to a Bluetooth module in the same way I want to send commands to esp module but here we need an App which first connects to a given IP address and then send a command on button click
Thank you

If you don't want to open a web page on the screen, use the Web component instead of the WebViewer.
The URL handling should be the same.

Did the WebViewer solution I posted actually influence the esp8266 ?

IP addresses and clients don't maintain connections like BlueTooth does.
Notice how all the URLs used to talk to the esp8266 fully specify the IP address and port in addition to the current command. It's like sending post cards.

Yes your App sends commands and esp receives them as indicated by blue led on it. And arduino inbuilt led but my output is not changed. It seems that wrong commands are being set.
See my experimental results on serial wifi terminal app from play store.
I open it and add a new device then I enter esp NAME or SSID then IP and then PORT

,
Then I click on it and this screen appears and I write just my command not IP or port I write FA and hit send button , which starts my arduino code perfectly.. See below

But in wifi widget app I need to send Command along with IP and PORT.
So serial app is working..
That is why I believe that esp can work like Bluetooth by just receiving Commands provided ssid etc are set in the app.
But I can not rely on serial App as it is only for experimental purposes and not user friendly , we need to enter command manually.

This discussion is about two separate issues ...

  1. Can Ai2 send a command to your device that it reads and understands?
  2. Can AI2 support a GUI design to hide that back end stuff behind buttons in a way you like?

If my sample app successfully satisfied item 1 (I am not sure about that), design your own GUI in the Designer, post the .aia file here, and let us show you the back end blocks to send the commands from your GUI.

If my sample app's commands were not understood by your device, we need to have a discussion about the difference between the RAW protocol used by your TERMINAL app and the HTTP protocol used by the Web component.

I'm not ready for such a discussion, especially since I don't see your Arduino code anywhere in this thread.

ESP_2.aia (11.4 KB) This is my .ino file very simple code also sets AT commands

[code]
volatile char MY_DATA1[60];
volatile unsigned char k1 = 0,
CC1=0,RX1 = 0,D = 0;
void setup()
{
// relay out put pin control.//
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
// Initial setup //
Serial.begin(9600);
// Initial ESP8266 //
ESP8266_INIT();
}
void loop()
{
// receive data from ESP8266 //
if(Serial.available())
{
MY_DATA1[k1] = Serial.read(); // read receive data from wi-fi module.
CC1 = MY_DATA1[k1];
if(CC1 == ':')D = k1;// check weather data scan start or not.
k1++;
if(CC1 == '\n'){k1=0;RX1 = 1;} // chaeck new line character are receive or not.
}
// Processing  data which are receiving  from ESP8266 //
if(RX1 == 1)
{
if(MY_DATA1[D] == ':')
{
MY_DATA1[D] = '0';
if(MY_DATA1[D+1] == 'F')
{
MY_DATA1[D+1] = '0';

if(MY_DATA1[D+2] == 'A')//switch 1 on
{
MY_DATA1[D+2] = '0';

digitalWrite(10,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'B')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(10,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'C')//switch 2 on
{
MY_DATA1[D+2] = '0';
digitalWrite(11,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'D')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(11,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'E')//switch 3 on
{
MY_DATA1[D+2] = '0';
digitalWrite(12,LOW);
RX1 = 0;
          }
else if(MY_DATA1[D+2] == 'F')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(12,HIGH);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'G')//switch 1 on
{
MY_DATA1[D+2] = '0';
digitalWrite(13,LOW);
RX1 = 0;
}
else if(MY_DATA1[D+2] == 'H')//switch 1 off
{
MY_DATA1[D+2] = '0';
digitalWrite(13,HIGH);
RX1 = 0;
}
     }
}
RX1 = 0;
}
}
void ESP8266_INIT()// initializing wi-fi module.
{
Serial.println("AT");// check AT mode.
delay(1000);
Serial.println("AT+RST");//RESET module.
delay(3000);
Serial.println("AT+CWSAP=\"YOUNUS \",\"87654321\",3,2");//set the ssid and password."Home Automation","2231anto",3,2

 delay(1500);
Serial.println("AT+CWMODE=3");// set ESP8266 in MODE 3 (Both mode AP+station).
delay(1400);
Serial.println("AT+CIPMUX=1");// set ESP8266 in MUX 1 (allow multiple connection).
delay(1400);
Serial.println("AT+CIPSERVER=1,80");// start communication ESP8266 on PORT80.
delay(1500);
}[/code]

I have removed some description text to keep it short.

Terminal App uses SSH, TELNET and RAW Protocols only.

I have Uploaded aia file see above ESP_2 as previous was not detailed this is my App interface without code blocks see also simple arduino sketch.
thank you.

This is my best try at matching your Arduino codein AI2 Web traffic.

From what I see in your code, you require ':\n' as a prefix for all traffic.
Change that in the AI2 common send procedure if I got that wrong.

Also, your comments in the Arduino code don't match the registers you switch once you get past led 1, so you will have to adjust your codes once you get led 1 working.

ESP_2_ABG.aia (13.0 KB)

I don't see why you have to trash your input buffer with '0' characters or maintain two cursors into it (k1 and D).

A text display on the Arduino side would be a big help for debugging.