Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By cicciocb
#45236 Since the introduction of the UDP commands, some new interesting things are possible.
One simple thing is to use it as a debugger console.
Many of us use the serialprintln command as a way to display debug information during the development of a basic program; this reaches the limits when the serial port is required to interface with some piece of HW.
One simple idea is to use the UDP to "print" the messages on the network recovering them with a simple utility.
I developed for that a little utility available here https://github.com/cicciocb/UDP_tester/ ... e?raw=true
This is a picture of the utility running on my PC
udpdebugger1.png

As you can see, the local IP of my computer is 192.168.1.69 and is listening on the port 5001 (localport)
So, to send a message to my PC from the ESP the command is

Code: Select alludpwrite "192.168.1.69", 5001, "message"


for example this simple ESPBasic program :
Code: Select allfor i = 1 to 1000
udpwrite "192.168.1.69", 5001, str(i)
next i


gives this result on the utility
udpdebugger2.png


If you want also be able to modify "dynamically" the value of a variable, your program will become :
Code: Select all'listening port
udpbegin 5001
ret = ""
'where the program will branch on UDP message reception
udpbranch [udp]
for i = 1 to 10000
udpwrite "192.168.1.69", 5001, str(i)
serialprintln ret
next i
end

[udp]
ret = udpread()
if ret = "stop" then end
return


This example runs for 10000 cycles printing the value of the var 'ret' that is initially empty.
We can use now the Utility to send a message toward the ESP.
To do that, we can simply write the message in "Message to Send" and click 'Send'; the message will be printed on the serial port.

As the address is automatically configured as broadcast, you don't need to put the exact IP of the ESP module.
udpdebugger3.png

As you may have noted, typing 'stop' will interrupt the basic program; this is very useful when the program fall into an endless loop obliging to reset the module.


Hoping this will be useful to someone.

CiccioCB
You do not have the required permissions to view the files attached to this post.
User avatar
By Mmiscool
#45240 This is very nice. Will make it much easier to find problems with a module that there is no serial connection to.
User avatar
By Electroguard
#45257 Thanks cicciocb, the UDP_debugger works spot-on, and is much better than running a udp Processing script.
Some good udp debugging tips as well - I've been using loads of udpreply statements to show variables and script progress, but as you point out, so much more is possible.
Thanks again.
User avatar
By cicciocb
#45283 Thanks for your feedback.
We are working to stabilise the current version in order to reduce as much as possible the crashes.
We know that many crashes comes from syntax error in the commands so we should improve the error checking avoiding to fall in this situation. The problem is that this chip has very limited resources in terms of RAM memory available and, finally, we must deal with this limitation.
Other improvements will come, I hope, in particular on the error checking.