Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Atmega8
#58305 Hello,

i would like to use ESPBASIC for a transparent WIFI Uart Bridge.
Background:

Would like to configure Hardware over Serial-Port, like Switches Routers and other stuff, with simply connecting over WIFI and using a Terminal Programm like Putty.

Can please anyone give me an Example how to do the "Basic" programming in ESPBasic?
Must be something like creating a socket, open the Serial port and sending each Byte from the Serial over wifi to the Putty Client and vice versa....

Thank you in advance,

atmega8
User avatar
By Electroguard
#58311 So you wish to send local serial commands via wifi to manage remote serially controlled devices, therefore no browser gui involved anywhere, right?.

There are many ways of skinning the same cat - but one way is to have your local ESP connected to your local computer Serial terminal via usb com port, so you can have your ESP branch when receiving serial info...

SERIALBRANCH:
Defines a branch to be executed when serial input is received.
serialbranch [branchLabel]

Example
serialbranch [serialin]
wait

[serialin]
serialinput zz$
Serialprint “received:”
serialprintln zz$
return


Trim off the end linefeed character then udp broadcast the received data using...

Udpwrite:
Write a string toward a remote IP and port
udpwrite {ip_address}, {port}, {message}
ip_address is a string (ex: “192.168.1.123”)
message is a string (ex: “This is a valid message”)
port is a number (ex: 5000)

Example: udpwrite “192.168.1.12”, 3000, “Message OK”


Obviously for 2 way coms you would need to do the same serial to udp broadcast on both local and remote devices.
Ditto for the udp to serial side of things, which would be done with...

UdpBranch:
Define a branch label defining the place where the program will continue as soon as an UDP message is received. As soon as the return command is found, the program will continue from the interrupted point.
To works, the UDP server needs to be open (commands UdpBegin or udpBeginMultiCast)
udpBranch {label}

Example:
udpbegin 4567
udpbranch [udp.received]
wait

[udp.received]
let rec = udpread()
let rem = udpremote()
Serialprint “Message received “ & rec & “ from “ & rem
udpreply “OK”
return


I've only copied the relevent examples directly from the documentation, so you'll obviously need to massage things to suit, but if I've picked up on your question correctly, that should give you all the basic mechanisms you will need.
User avatar
By Atmega8
#58332 Hello Electroguard,

thank you for this fast Answer. I ' am not sure if i have explained it in the right way.
Try it again.
No Webbrowser involved.

Site 1 with device to configure:
Router/Switch with rs232 connection to ESP8266.

Site 2 where i would like to configure device from sitze 1.
A PC with Terminalprogramm (putty) opens Telnet connection
via UDP or TCP (Port and IP of the Esp8266) over WIFI to "listener" on Site 1 (ESP).
Every Byte send from Site 1 should arrive an be printed in the Putty Session on the PC,
and every Byte send from the Putty session from Site 2 should arrive the device on site 1.

OK?
User avatar
By Electroguard
#58337 Yes, I thought that's what you were asking. You're gonna be pleasantly surprised, because Mmiscools Esp_Basic actually makes that 'techie' job very eazy-peazy, particularly because of its simplicity for the handling of incoming event-driven serial and udp messages.

So my answer is correct for your needs. Re-read, as you try to relate to the following simple diagram and hopefully it should make some sense.

(Computer)--Serial<>UDP ...........(wifi)............ UDP<>Serial--(Remote)

I'm guessing you are new to Esp_Basic, so if you don't already have a couple of ESP devices yet, I suggest you get 4Mb versions rather than 512K or 1MB, cos it will give sufficient memory for all the Esp_Basic debugging features to make the small learning curve even easier.