Skip to content
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

ESP-01 WiFi modem (AT command) #169

Open
MykolaKyrylenko opened this issue Aug 30, 2021 · 44 comments
Open

ESP-01 WiFi modem (AT command) #169

MykolaKyrylenko opened this issue Aug 30, 2021 · 44 comments
Assignees
Labels
open for vote Vote at https://wokwi.com/features

Comments

@MykolaKyrylenko
Copy link

Would it be possible to add the equivalent of an ESP-01 component for integrating to an Arduino Uno or Mega project at a WiFi modem. Some ideas:

Thanks.

@urish urish self-assigned this Aug 31, 2021
@urish
Copy link
Contributor

urish commented Aug 31, 2021

Thanks for the suggestion @MykolaKyrylenko !

Would an ESP32 simulation also fit for your use case? Or do you need at ESP-01 specifically?

@MykolaKyrylenko
Copy link
Author

Thanks for the response.
I am flexible with the implementation, so an ESP32 will be good.
Are you intending an AT command interface?

@urish
Copy link
Contributor

urish commented Sep 1, 2021

Are you intending an AT command interface?

Not at the moment. But if you run your code directly on the simulated ESP32, you should be able to use the WiFi functions directly. Does this not fit your needs?

@MykolaKyrylenko
Copy link
Author

I lecture at a technical college, and we are using the Atmel processor on the Arduino Mega to teach low level C programming, e.g. DDR, PORTC, etc. registers. The ESP32 will be too complicated for our students.
We are trying to incorporate IoT thinking, and I believe the simplest way it to have a "WiFi modem", with AT commands and a serial interface.
I would prefer not to change processors / boards part way through the topic.

NOTE: in industry I had to integrate a cellular modem to a microcontroller, and that worked well.

@urish
Copy link
Contributor

urish commented Sep 11, 2021

Got it. Yeah, ESP32 is indeed pretty complex.

There might be a way, at some point, to run both the AVR and ESP32 simulators in different tabs and have them communicate over virtual UART, which may be helpful.

How long until you get to teaching the WiFi modem part?

@MykolaKyrylenko
Copy link
Author

Thanks for that. Either solution will be great.
We are teaching the WiFi modem part in about 4 weeks, so I do not expect this feature this semester. But we teach this topic each semester, so it will be great for the future.

PS I noticed another enhancement request, was using WebSockets. Can something be done with that work?

@MykolaKyrylenko
Copy link
Author

I had an interim solution, if that is of interest.

Would it be possible to have a 'serial' device which just sends a HTTP POST request?
e.g. https://randomnerdtutorials.com/cloud-weather-station-esp32-esp8266/
[same hardware interface as my original post]

@MykolaKyrylenko
Copy link
Author

PS to my previous comment. Sort of like the CURL command (https://curl.se/) to generate HTTP requests.

@urish urish added the open for vote Vote at https://wokwi.com/features label Sep 16, 2021
@urish
Copy link
Contributor

urish commented Oct 5, 2021

Sorry - I forgot to reply to your suggestions :)

There's a way to achieve what you suggested with the features that we already have, though it's not very straightforward (and also undocumented):

  1. Use the Chrome browser
  2. Use wokwi-serial-port together with a virtual com port driver (see here for details)
  3. Write some script that will read the requests from a serial port (e.g. a curl command), perform them, and write the result back to the serial port. You could probably do with with python + PySerial.

I'm pretty positive that we'll have something usable for the next semester. You can track the roadmap in the public features page.

How's the semester going so far?

@MykolaKyrylenko
Copy link
Author

Thanks for the message.
Some of our students are remote, so doing your suggestion will confuse them. For this purpose, I am getting them to use real hardware. It will be great to have something by next semester.

Overall, the students are loving Wokwi. I needed to adapt bits due to known limitations, e.g. resistor divider network cannot be created for A/D conversion, so I used the potentiometer slider instead. A full integration of Wokwi and Falstad will be gold.
Great work.

@urish
Copy link
Contributor

urish commented Oct 9, 2021

Thanks for the feedback!

I opened a new issue (#203) for the resistor divider network, it's now also open for vote. Let's see how much love it gets!

@urish
Copy link
Contributor

urish commented Mar 27, 2022

This one is getting many votes recently, making its way to the top of the list. We may start working on it soon if it keeps coming up the list!

@urish
Copy link
Contributor

urish commented Apr 24, 2022

Some updates: I'm looking into using the official ESP-AT Firmware on ESP32-C3 to provide this functionality. Anyone interested in beta testing?

@MykolaKyrylenko
Copy link
Author

I would be interested. Do you think the ESP32-C3 can be included with an Arduino on the same project?

@urish
Copy link
Contributor

urish commented Apr 25, 2022

Thanks! In general, it is not possible to run two MCUs at once (at least until we tackle #186).

For the AT modem specifically, I'm working to make it possible. I'll share the details about the beta testing here in a few days.

@urish
Copy link
Contributor

urish commented Apr 30, 2022

So, here's something working - you can interact with the modem directly through the virtual serial monitor:

https://wokwi.com/projects/330317327704785492

The performance is pretty bad, and I haven't tried to connect it with an Uno yet (but in theory, that should also work). The only way to connect it is through diagram.json, as there's no UI element yet.

The WiFi works similar to how it does in the ESP32 - same access point configuration, uses the same gateway settings, etc.

@ricardojlrufino
Copy link

WoW ...

I tested it here, by the messages I saw that it is simulating very real...
Are you using real hardware on the server side??

image

@urish
Copy link
Contributor

urish commented Apr 30, 2022

Thanks @ricardojlrufino! Behind the scenes, we're simulating the ESP-AT firmware using the same simulation engine that powers the ESP32 simulation. So it's not real hardware, but your questions shows that we are probably doing pretty good job with the simulation :-)

@ricardojlrufino
Copy link

yes ...
failures are often good signs that things are working... =]

@urish
Copy link
Contributor

urish commented Apr 30, 2022

Some more updates: the performance is now somewhat better (the simulation runs at 100% speed on my PC), and also fixed some issues with the UART output (wrong baud rate, missing chars when there's a lot of output, etc.).

So it should already be usable now. It will probably take some time until I get to create the board graphics, though.

@MykolaKyrylenko
Copy link
Author

Excellent work. I had similar results to Ricardo. Very fast performance.

I am assuming IP addresses are not being fed at the moment?
image

@urish
Copy link
Contributor

urish commented Apr 30, 2022

Thanks! This was a bug - can you please try again now?

@MykolaKyrylenko
Copy link
Author

Excellent:
image
AT+CWMODE=1 had instant resppnse
AT+CWLAP responded in a few seconds
AT+CWJAP repsonded with 'WIFI CONNECTED' instantly, and then after about several more seconds completed the response

@urish
Copy link
Contributor

urish commented May 1, 2022

Hooray :)

If anyone gets a chance to test this with the Uno (or other Arduino board), I'd love to learn how it works

@MykolaKyrylenko
Copy link
Author

I tried it with the Mega using Serial 1. The code is very crude, but commands get sent and responses are received. Works well.
Responses appear on Serial Monitor.
See here: https://wokwi.com/projects/330589181982016082

@urish
Copy link
Contributor

urish commented May 3, 2022

Cool! I see you also tried to get an HTTP request working, any luck with that yet?

@MykolaKyrylenko
Copy link
Author

I managed to get a POST request received on our server:
image

The AT+HTTPCLIENT came back with an error:
image

@urish
Copy link
Contributor

urish commented May 4, 2022

Interesting, so it sent the POST request, but then said "ERROR" without telling anything else.

Do you have a physical ESP chip to try it and see if you get a different result?

@MykolaKyrylenko
Copy link
Author

MykolaKyrylenko commented May 4, 2022

I have a physical ESP-01, and will try to get it going.

Some more information:
I sent a single POST request and 11 messages appeared on the server, with a 1 second gap between them.
image
Could be a timeout issue?

CURL command did as expected, with only 1 record sent:
image

@urish
Copy link
Contributor

urish commented May 4, 2022

Downloading a PCAP packet capture could be helpful to understanding what's going on

@MykolaKyrylenko
Copy link
Author

The 'Download WiFi Packet Capture (PCAP) file' option does not appear on my project.
Is this option only for ESP-32 projects? Mine is Arduino Mega.

@urish
Copy link
Contributor

urish commented May 5, 2022

It only appears after a simulation with WiFi has been running. I ran it now, and I think I spotted the issue:

image

Your server is responding with a redirect. I guess the AT firmware doesn't know how to handle that, so it retries the request several times, until it eventually gives up and says "ERROR".

@MykolaKyrylenko
Copy link
Author

My server is a VPS on Binary Lane (https://www.binarylane.com.au/), and running standard Ubuntu + Apache.
I have not had time to plug in the ESP-01, but will attempt to soon.

Note: when I historically used the "WiFiEsp.h" library, it worked well.

@MykolaKyrylenko
Copy link
Author

My Espresiff firmwareis old
image
and does not have the AT+HTTPCLIENT command.
I will try to re-flash, or work our what command "WiFiEsp.h" library uses.

@MykolaKyrylenko
Copy link
Author

I tried with WiFiEsp library and no joy, even to initialise the ESP32-01
https://wokwi.com/projects/330956422342771284
I will keep on investigating...

@MykolaKyrylenko
Copy link
Author

Seems to work here without retries: https://wokwi.com/projects/330962510931821139

Note: intially, I tried to send the POST message with no delays between the characters, and I got a bad request error. By slowing down the data with 100msec delays (lines 84 - 91) the request was accepted without error.

@urish
Copy link
Contributor

urish commented May 7, 2022

Thanks for sharing your findings!

@urish
Copy link
Contributor

urish commented May 12, 2022

Update: The ESP32-01 now has graphics too, thanks to @AriellaE.

The part name has changed to board-esp-01, and I have updated the example:

https://wokwi.com/projects/330317327704785492

Next steps: documentation, add the the part to the dropdown menu.

@MykolaKyrylenko
Copy link
Author

Excellent.
Looks good: https://wokwi.com/projects/330962510931821139

@urish
Copy link
Contributor

urish commented May 14, 2022

Lovely :)

@rovoegit
Copy link

I tried with WiFiEsp library and no joy, even to initialise the ESP32-01 https://wokwi.com/projects/330956422342771284 I will keep on investigating...

The newer library WiFiEspAT works with the ESP-01 Shield!
--> https://wokwi.com/projects/371794654687376385

I think it works because the wokwi ESP-01 shield has a newer firmware wich is supported by the new library.

@ghost
Copy link

ghost commented Mar 19, 2024

Note:

Using VSCode, in order for the following to work:

// disconnect persistent connection (not persistent)
WiFi.disconnect();

WiFi.begin("Wokwi-GUEST");

you need to comment this line:

#define WIFIESPAT1

in .pio/libdeps/<board>/WiFiEspAT/src/utility/EspAtDrvTypes.h

@gsingh93
Copy link

gsingh93 commented Mar 31, 2024

Thanks @CreativeQuantum, I was about to give up on using WiFiEspAt until I saw your comment (although now I see this information is in the README, I had missed it).

An easier way to do this, without modifying the library, is to add -DWIFIESPAT2 to the build flags. For PlatformIO, that would look like build_flags =-DWIFIESPAT2.

WiFiEspAt says they support firmware 2.4.0+, but Wokwi is running 2.3.0:

AT+GMR
AT version:2.3.0.0(e98993f - ESP32C3 - Dec 23 2021 09:03:35)
SDK version:v4.3.1-354-g98d34e5
compile time(9ff1373):Dec 24 2021 11:22:05
Bin version:2.3.0(MINI-1)

So far I haven't run into any issues, but it may be worth upgrading it.

@ghost
Copy link

ghost commented Mar 31, 2024

Excellent work, glad there are other super heros fighting crime, huh, I mean, software complexity (which is a kind of crime of its own).

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

No branches or pull requests

5 participants