I’ve managed to successfully send data over wifi with Rust. I’m basing my work on the RISC-V Rust quickstart repo, specifically the
spi_wifi.rs example. I built a small REPL using some code I wrote to read user input and the code in that example to read the responses from the ESP32. I also referenced the ESP32 AT Instruction Set manual pretty heavily, especially the documentation for the
AT+CIPSEND commands. Something that I didn’t realize when starting working with the chip is that it’s chattier than I expected: I needed to make multiple calls to the
recv() function in the
spi_wifi.rs example to empty the response buffer from the ESP32. Further, chapter 9 of the ESP32 manual is especially helpful: it contains sample conversations for several basic tasks.
I’m including my successful conversation log below, and should eventually have something more polished up on github for folks to play with. I want to point out that what I have is very hacky and ugly, but it works. I call
recv() three times, as that seems to be enough to cover all the different cases. The right way to approach this would be a state machine, and I’ll look at building one for this when I put code up on github.
Ok("WIFI GOT IP\r\n")
wifi> AT+CIPSTART="TCP","REMOTE IP",1234
Ok("\r\nRecv 7 bytes\r\n")
AT+CIPSEND=7 because the code I have for my REPL appends
\r\n to everything sent to the ESP, and the board reads everything you send after as what to send up to that number of bytes, so I had to account for the two extra bytes after the obligatory
hello string (I did mention the code is ugly and hacky). The
Err(WouldBlock)s here indicate superfluous
recv() calls, as I described above. To receive data, I used
nc -kl 1234 on my Mac. Usually,
nc quits after the first connection, but
-k keeps the program listening after clients disconnect. Helpful when debugging a client!