Skip to content

WiFi Support for ESP32 / ESP32-S2 #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
urish opened this issue Oct 5, 2021 · 30 comments
Closed

WiFi Support for ESP32 / ESP32-S2 #202

urish opened this issue Oct 5, 2021 · 30 comments
Labels
enhancement New feature or request open for vote Vote at https://wokwi.com/features

Comments

@urish
Copy link
Contributor

urish commented Oct 5, 2021

WiFi support will allow you to connect to various hosts on the internet using standard protocols and standards: MQTT, REST, WebSockets, etc.

@urish urish added enhancement New feature or request open for vote Vote at https://wokwi.com/features labels Oct 5, 2021
@pixavier
Copy link

Using MQTT with libraries like PubSubClient.h would be great. It would allow the development of complete projects with digital twins of embedded systems, a significant advance in the democratization of teaching in schools.

@urish
Copy link
Contributor Author

urish commented Oct 29, 2021

Once we have WiFi support in place, MQTT libraries should work. I noted to check PubSubClient in particular.

The WiFi features currently has 45 votes.

@urish
Copy link
Contributor Author

urish commented Nov 9, 2021

Some progress update: managed to establish a connection to an open WiFi network within the simulation!

https://twitter.com/WokwiMakes/status/1457805832977063936

There's still much to be done, but this is one milestone :-)

@pixavier
Copy link

pixavier commented Nov 9, 2021

Very ecouraging Wireshark screenshot !
Closer and closer to an MQTT message capture.

@urish
Copy link
Contributor Author

urish commented Nov 9, 2021

One packet at a time :)

@urish
Copy link
Contributor Author

urish commented Nov 13, 2021

Replying to @lzzy12's comments from another issue:

Does that mean we will be able to run webservers and run standard IOT simulations?

Yes, that's the plan.

@urish
Copy link
Contributor Author

urish commented Nov 18, 2021

MQTT works!

I managed to successfully connect to an MQTT server from within the simulation, send and receive messages, using MicroPython (+ umqttsimple):

image

HTTP works too. SSL does not - we'd need the hardware-accelerated AES peripheral.

@pixavier
Copy link

Great !

@pixavier
Copy link

I'm trying to connect to WiFi to test the pubsubclient library (https://github.com/knolleary/pubsubclient/tree/master/src), but I'm not able to connect (https://wokwi.com/arduino/projects/315894638733951554).

@lzzy12
Copy link

lzzy12 commented Nov 21, 2021

I'm trying to connect to WiFi to test the pubsubclient library (https://github.com/knolleary/pubsubclient/tree/master/src), but I'm not able to connect (https://wokwi.com/arduino/projects/315894638733951554).

I think it's still in testing phase and not yet pushed to production

@pixavier
Copy link

I'm trying to connect to WiFi to test the pubsubclient library (https://github.com/knolleary/pubsubclient/tree/master/src), but I'm not able to connect (https://wokwi.com/arduino/projects/315894638733951554).

I think it's still in testing phase and not yet pushed to production

OK

@urish
Copy link
Contributor Author

urish commented Nov 22, 2021

I think it's still in testing phase and not yet pushed to production

Indeed - it will probably be in production in a few days. Meanwhile, I ran @pixavier's project, and it seems to work well in the testing environment:

image

@pixavier
Copy link

Wow !

@lzzy12
Copy link

lzzy12 commented Nov 27, 2021

It's been few days, is it out yet?

@urish
Copy link
Contributor Author

urish commented Nov 27, 2021

Partially. You can try connecting to Wokwi-GUEST, and hopefully get some internet access. Not thoroughly tested, no code examples and and no user interface indication yet, so your milage may vary..

@lzzy12
Copy link

lzzy12 commented Nov 27, 2021

#include <WiFi.h>

const char* wifi_name = "Wokwi-GUEST"; //Your Wifi name
const char* wifi_pass = "";    //Your Wifi password

void setup()
{
    Serial.begin(115200);
 
    // Let's connect to wifi network 
    Serial.print("Connecting to ");
    Serial.print(wifi_name);
    WiFi.begin(wifi_name, wifi_pass);       //Connecting to wifi network

    while (WiFi.status() != WL_CONNECTED) { //Waiting for the responce of wifi network
        delay(500);
        Serial.print(".");
    }
    Serial.println("");
    Serial.println("Connection Successful");
    Serial.print("IP address: ");
    Serial.println(WiFi.localIP());         //Getting the IP address at which our webserver will be created
    Serial.println("Put the above IP address into a browser search bar");
}

I tried this but it seems it just gets stuck in the while (WiFi.status() != WL_CONNECTED) loop endlessly.
Am I missing something?

@pixavier
Copy link

Izzy12, can you try again ? It worked for me.

image

@lzzy12
Copy link

lzzy12 commented Nov 27, 2021

Izzy12, can you try again ? It worked for me.

image

Yeah It started working after I called the WiFi.mode() method. pretty weird.

@pixavier
Copy link

pixavier commented Nov 27, 2021

Closer and closer: https://wokwi.com/arduino/projects/316434364352168512

After a few seconds, it stops receiving messages, and after a while, it loses the MQTT connection and cannot reconnect.
(Tested with Chrome on Windows 10. Extremely slow with Firefox)

image

@urish
Copy link
Contributor Author

urish commented Nov 28, 2021

Thanks for checking it!

There seems to be something iffy with the websocket proxy, I'll have to investigate why this happens.

What is the performance difference you are observing between Firefox / Chrome?

I see in your screen shot chrome gets around 9%. What do you get on Firefox?

Does adding delay(10); to loop() help?

@pixavier
Copy link

pixavier commented Nov 28, 2021

Thanks for checking it!

There seems to be something iffy with the websocket proxy, I'll have to investigate why this happens.

What is the performance difference you are observing between Firefox / Chrome?

I see in your screen shot chrome gets around 9%. What do you get on Firefox?

Does adding delay(10); to loop() help?

Connection times:

    Chrome  Firefox

WiFi 16" 1'21"
MQTT 17" 1'23"

Firefox also 9%

delay(10) appeared to improve the situation, but MQTT does not connect anymore after some seconds, less than a minute.

Digital Twin (DT) link:
https://wokwi.com/arduino/projects/316434364352168512

Snap! based DT test environment:
http://www.xavierpi.com/snap/snap.html#open:http://www.xavierpi.com/dt/mqtt_esp32-text.xml

@pixavier
Copy link

Two days working with it. Fairly good for prototype development and testing purposes. Sometimes, after some minutes ([1, 10]), MQTT loses connection, but one can continue testing by restarting the simulation again.
Very, very interesting. Thanks a lot, Uri.

@lzzy12
Copy link

lzzy12 commented Nov 30, 2021

We're not able to host our own webserver right now, are we? I'm not able to connect to the ip address after starting the webserver

@urish
Copy link
Contributor Author

urish commented Nov 30, 2021

Two days working with it. Fairly good for prototype development and testing purposes. Sometimes, after some minutes ([1, 10]), MQTT loses connection, but one can continue testing by restarting the simulation again.

Thanks for the feedback! I believe this is an infrastructure issue. Do you have a specific use case for this or are you just playing around to explore what's possible?

We're not able to host our own webserver right now, are we? I'm not able to connect to the ip address after starting the webserver

Can you explain more about your setup? Where is the web server running and where are you trying to connect to it from?

@lzzy12
Copy link

lzzy12 commented Dec 1, 2021

Can you explain more about your setup? Where is the web server running and where are you trying to connect to it from?

I was just trying to follow a few lectures from my university. Here is an article with something similar I was trying to do: https://randomnerdtutorials.com/esp32-web-server-arduino-ide/

@pixavier
Copy link

pixavier commented Dec 2, 2021

Thanks for the feedback! I believe this is an infrastructure issue. Do you have a specific use case for this or are you just playing around to explore what's possible?

We are preparing sensors and actuators combined with Node-RED and MQTT4Snap! examples for teaching purposes. Many of them will be open, so I will inform you when they will be available online.

@urish
Copy link
Contributor Author

urish commented Feb 3, 2022

Good news: WiFi support is now done for the ESP32!

You can check out the documentation, including code examples and explanation about how to connect it to the Internet:

https://docs.wokwi.com/guides/esp32-wifi

@lzzy12 - there's also a way to host your own webserver on the ESP32 using the Private Wokwi IoT Gateway. You can see it in action in this video:

esp-http-server-leds.mp4

The ESP32-S2 is still missing some bits, so it doesn't have a functional WiFi at the moment. We'll continue working on it as we improve the ESP32-S2 simulation as part of #196.

Finally, I want to thank everyone who supported and helped testing this feature. As a token of appreciation - if anyone who participated in this thread wants to have access to the Private Wokwi IoT Gateway, just let me know (+ send me a link to one of your Wokwi projects so I can find your user id). For others - you are always invited to join the club and help make Wokwi better.

@urish urish closed this as completed Feb 3, 2022
@pixavier
Copy link

pixavier commented Feb 25, 2022 via email

@lzzy12
Copy link

lzzy12 commented Feb 25, 2022

Mine is https://wokwi.com/arduino/projects/319226828692652627

GitHub.com/lzzy12
I underlooked the thread few days ago :)

@urish
Copy link
Contributor Author

urish commented Feb 25, 2022

You both @pixavier and @lzzy12 should now have access to the Private IoT Wokwi Gateway when you are logged-in.

Here are the full instructions. Please check it it works for you and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request open for vote Vote at https://wokwi.com/features
Projects
None yet
Development

No branches or pull requests

3 participants