Android Question Controlling the ESP8266 over wifi

ardhuru

Member
Licensed User
Longtime User
Please bear with me, I am a complete novice with B4A.

A few months back, after lookimg at a lot of samples, I designed an app that shows a numeric keypad, and using asyncstreams over bluetooth, transmits a number corresponding to the key that was pressed.

Now, I would like to implement the same thing, but with Wifi. On the reception side, I'll probably use an ESP8266 serial to Wifi module. I feel fairly confident of writing the code for the ESP8266.

So, how do I go about it on the Android? For starters, what would be used in place of asyncstreams? I suspect it would be httputils, but I have absolutely no idea where to start.

I can probably make it happen using a browser, but I'd like to create an app that has my custom buttons, and an interface designed in the abstract designer.

Any pointers would be highly appreciated!
 

ardhuru

Member
Licensed User
Longtime User
Freedom2000, welcome aboard!

XorAndOr, my application is a simple numeric keypad on my phone that would be used to open my main door. I can write all the code for this.

On the ESP side, I'll connect a pic that will decode the series of numbers, and operate the relay if the code matches. No problems here either.

Now, for some reasons (range being one of them) I'd like the ESP to act as a soft AP, and not involve my router at all.

But, my cellphone would be by default connected to the router. Therefore, ideally, I'd like the app running on the mobile to specifically connect to the ESP (soft AP mode) when executed, do its business, and while exiting hand over connection of the phone back to the router.

Is this do-able?

BTW, your sample LUA codes for the ESP have been a great starting point, and will work as a basis for my own code, thanks.

Regards,

Anand
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
Freedom2000, welcome aboard!

XorAndOr, my application is a simple numeric keypad on my phone that would be used to open my main door. I can write all the code for this.

On the ESP side, I'll connect a pic that will decode the series of numbers, and operate the relay if the code matches. No problems here either.

Now, for some reasons (range being one of them) I'd like the ESP to act as a soft AP, and not involve my router at all.

But, my cellphone would be by default connected to the router. Therefore, ideally, I'd like the app running on the mobile to specifically connect to the ESP (soft AP mode) when executed, do its business, and while exiting hand over connection of the phone back to the router.

Is this do-able?

BTW, your sample LUA codes for the ESP have been a great starting point, and will work as a basis for my own code, thanks.

Regards,

Anand
Hi,

First I am sure that you don't need a PIC for doing this simple APP. The basic ESP8266-01 + NodeMCU will do the job

The main difficulty is on Android side as I am not sure that switching for router to AP and then again to router is doable under B4A...
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
For all of you who have played with the ESP8266 :)

Has anyone modified the AT firmware (or any other which is not LUA) for its own purposes?
I tried to setup the SDK (following advices in different pages ) in windows, using Cygwin, but found an ugly problem with pathnames. I wonder if someone has setup this environment with windows or virtualbox/linux and been able to compile.
 
Upvote 0

ardhuru

Member
Licensed User
Longtime User
Freedom2000, I realize my application can be implemented on the ESP8266 itself. But, I'm far more comfortable using pics (Picbasic Pro) than LUA, or the AT command set.

JordiCP, The Arduino IDE now supports the ESP8266 directly (without having to use an Arduino)> If you are used to the Arduino environment, you'll find it extremely easy to use that, rather than LUA. https://hackaday.io/project/5150-arduino-ide-for-esp8266-quickstart-guide

Regards.
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
Now, for some reasons (range being one of them) I'd like the ESP to act as a soft AP, and not involve my router at all.
But, my cellphone would be by default connected to the router. Therefore, ideally, I'd like the app running on the mobile to specifically connect to the ESP (soft AP mode) when executed, do its business, and while exiting hand over connection of the phone back to the router.


hello, I do not know if I understand what you should do your app, but if you can help take a look at this link, this lib connects and disconnects your mobile device that you have paired, esp8266 in fact is the one device. If you do not know how the lib work, I can write the sample code for you. greetings

https://www.b4x.com/android/forum/threads/wifi-manager-library.17150/
 
Upvote 0

freedom2000

Well-Known Member
Licensed User
Longtime User
For all of you who have played with the ESP8266 :)

Has anyone modified the AT firmware (or any other which is not LUA) for its own purposes?
I tried to setup the SDK (following advices in different pages ) in windows, using Cygwin, but found an ugly problem with pathnames. I wonder if someone has setup this environment with windows or virtualbox/linux and been able to compile.

HI

I successfully installed the windows toolchain following this link : http://www.esp8266.com/viewtopic.php?f=9&t=820&sid=783b2f3021078ab65722108fdfadd5d8#p4639
 
Upvote 0

ardhuru

Member
Licensed User
Longtime User
hello, I do not know if I understand what you should do your app, but if you can help take a look at this link, this lib connects and disconnects your mobile device that you have paired, esp8266 in fact is the one device. If you do not know how the lib work, I can write the sample code for you. greetings

https://www.b4x.com/android/forum/threads/wifi-manager-library.17150/

Success at last! Achieved preciesly what I had in mind. Could not have done it without that last pointer.

Thank you so much, XorAndOr!

Best regards.
 
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi XorAndOr

I try to test the Android code but getting some ERROR >>

Parsing code. Error
Exception of type 'System.OutOfMemoryException' was thrown.

i am used B4A 2.71

Regard

Mitesh
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
Hi XorAndOr

I try to test the Android code but getting some ERROR >>

Parsing code. Error
Exception of type 'System.OutOfMemoryException' was thrown.

i am used B4A 2.71

Regard

Mitesh
Hi, the example I attached works fine at least on my version 4.30, on Phone and Tablet.
I do not know exactly why that happens error, try to copy the code of the 'example on a project with version 2.71. Check if the libraries are updated, I use the Core version 4.01, for the Network version 1.25, and for RandomAccessFile version 2.00, it may be that your version of B4A not compatible with libraries. greetings
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Hell all, i have been keeping my eye on this thread, i must say this is all very interesting, i have an idea for a project i would like to implement using the ESP8266 wifi module, i have been doing a little bit of reading regarding the specifications and the capabilities of this module and i think it can be used for what i need.
I do have one question that i have not been able to find a clear answer to, and maybe you guys can answer it.
Can the ESP8266 be used in Direct-Wifi mode?
meaning can i connect to this module with my android device without the need for any network connection?
If so how can this be achieved?
My idea is this, i would like to connect the module directly to the serial port of a projector, using a ttl to serial converter of course, once the module is configured for this purpose, would I be able to talk to the module and send command to it in order to talk to the projector through the serial port?

Is the serial port on the module specifically to talk to the module only, or can it be used to talk to a microcontroller?

I really appreciate your help and advice in advanced.

Thanks All
Walter
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
Can the ESP8266 be used in Direct-Wifi mode?
meaning can i connect to this module with my android device without the need for any network connection?
Is the serial port on the module specifically to talk to the module only, or can it be used to talk to a microcontroller?
Hi, my little knowledge your project can be realized without any problem. For wifi-direct I use the tcp or udp with soft AP,
(no internet connection)for the communication with the (max232-serial)you have to use the (uart) module esp8266 tx-rx.
Of course you have to write the code for both the module esp for the app for Android.
For testing you can use a terminal windows, it is the same process that you want to do. However, this is my advice, other users of the forum can give you different opinions, do you see what is the ideal solution. greetings
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Hi, my little knowledge your project can be realized without any problem. For wifi-direct I use the tcp or udp with soft AP,
(no internet connection)for the communication with the (max232-serial)you have to use the (uart) module esp8266 tx-rx.
Of course you have to write the code for both the module esp for the app for Android.
For testing you can use a terminal windows, it is the same process that you want to do. However, this is my advice, other users of the forum can give you different opinions, do you see what is the ideal solution. greetings
Thanks for your reply, i will give it a try and keep you guys posted.

Thanks,
Walter
 
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi XorAndOr
i am open new projects and past the code now it's compiled without any error, but i am try to open in designer menu, getting error >>

Regard
Mitesh
 

Attachments

  • error.jpg
    error.jpg
    33.5 KB · Views: 273
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
but i am try to open in designer menu, getting error >>

hi, surely your version of B4A is not compatible with the attached example in post # 5 .... try this smaller version of the example and tell me if it's still not working.
 

Attachments

  • Test271.zip
    346.9 KB · Views: 557
Upvote 0

Mitesh_Shah

Member
Licensed User
Longtime User
Hi XorAndOr
Thanks for Example. it's compiled without any error in B4A 3.0. can u help how to run/ Modify "B4A ESP8266" Example in B4A ?
 
Upvote 0

XorAndOr

Active Member
Licensed User
Longtime User
can u help how to run/ Modify "B4A ESP8266" Example in B4A ?

Hi, in post #5 it is everything regarding communication between B4A, esp8266 and (optional) with a PIC16F876A, tested and running and also in use in a my project. If you explain in more detail what you want to do, both me and other people on the forum can help. The latest file that I attached if it works, you can edit it with the code of the post #5. On your project with version 2.71 or 3:00 you have to add the buttons and enter ONLY the code in the post #5. It should be easy. (google trasl.).
 
Upvote 0
Top