Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By forlotto
#33820 I do not understand quite how to read the status of the pin

It would be helpful to see an example of this

Code: Select all   msgbranch [mybranch]
    print "You can send msgs to the esp and do things based on accessing a URL"
    wait
    [mybranch]
    MyReturnMsg = "Not a valid msg received"
    msgget "pin" pinNo
    msgget "stat" pinStatus
    msgget "action" pinAction
    if pinAction == "po" then gosub [po.pin]
    if pinAction == "read" then gosub [readall.pin]
    print "DOne with retrn code"
    msgreturn MyReturnMsg
    wait

    [po.pin]
    po pinNo pinStatus
    MyReturnMsg = "good"
    return

    [readall.pin]
    read{pin1}{pin1s}
    if pin1s==0 then print "PIN1 ON"
    else print "PIN1 OFF"
    return


Note I added 1 pin... just to test out a possible way of doing so...
if I type http://192.168.x.x/msg?action=read
Not a valid msg error displays

How does one properly read the status of the pin being a 0/1?

I would like a webpage actually on load to read all pins and tell me if they are ON or OFF more or less and then handle writing high or low via URL the writing looks fine as per the example but I am unsure of how to read pins with basic?
User avatar
By Mmiscool
#33822 Hello,

The pi (pin input) command will retrieve a 1 or a zero from a pin depending on the high or low status.
More about the hardware interface commands can be found here.
http://www.esp8266basic.com/hardware-in ... mands.html
PI:
Will place the high or low status of a pin in to the variable chose.
Useful for reading push buttons and other electronic inputs.
pi {pin no} {var to place result 1/0}


I modified your code below so now it is working. Also note that spaces are required when evaluating if then expressions and can no be spread across multiple lines at this point in time.

I tested with pin 0 as on this phancy new node mcu board it has a push button to use for easy testing.

http://172.16.0.126/msg?pin=0&action=read

Code: Select all msgbranch [mybranch]
    print "You can send msgs to the esp and do things based on accessing a URL"
    wait
    [mybranch]
    MyReturnMsg = "Not a valid msg received"
    msgget "pin" pinNo
    msgget "stat" pinStatus
    msgget "action" pinAction
    if pinAction == "po" then gosub [po.pin]
    if pinAction == "read" then gosub [readall.pin]
    print "DOne with retrn code"
    msgreturn MyReturnMsg
    wait

    [po.pin]
    po pinNo pinStatus
    MyReturnMsg = "good"
    return

    [readall.pin]
    pi pinNo pinStatus
    if pinStatus = 0 then MyReturnMsg = "off" else MyReturnMsg = "on"
    return
User avatar
By forlotto
#33823 hrmmm... ok I'll have to tinker around this weekend a bit more and get the hang of this.

Maybe I could do a simple for loop somehow just to spit out all the pin values 0-16

or maybe this would work

for x = 0 to 16;
pi x
gosub {readalloutput]
if x = 16 then return else next x

[readalloutput]
if pinStatus = 0 then MyReturnMsg = <p>"Pin" print x " is OFF"</p> else MyReturnMsg = <p>"Pin" print x " is ON"</p>

totally new to basic if you can't tell but I'll figure it out just need more time.


Note to self:
Whenever I would run pi it would always return a 1 even while set to zero with default url code NOTE need to try again maybe I did something incorrect with the URL gotta look.

Anyhow no need to answer this one I am more so thinking out loud and marking my place in train of thought where I left off more or less.

Think of this posting as my notepad heh could have used my PC space but it helps if my notes are with previous questions asked just easier for me to post away.

PS Did you ever get to hook up the nodemcu and try it out?

But thanks.
User avatar
By Mmiscool
#33845
PS Did you ever get to hook up the nodemcu and try it out?


Yes. See earlier post.
I tested with pin 0 as on this phancy new node mcu board it has a push button to use for easy testing.



on a node mcu boar pin 0 is pulled high except when the button is pressed. Then it is pulled low.