![]() |
Forum Index : Microcontroller and PC projects : PicoMiteWeb firmware for the Pico W - now making real progress
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10068 |
Here is a new version to try - hopefully more robust and the DS18B20 issue should be improved PicoMiteWebV5.07.07a6.zip This also introduces an interrupt rather than polling the TCP requests. Note also that the maximum number of requests is increased to 8 It is highly recommended that you handle requests as below. It is efficient and seems robust (or at least more robust) WEB tcp interrupt TCPinterrupt do ' main loop loop ; sub TCPinterrupt local req% for req%=1 to mm.info(max connections) if not mm.info(TCP request req%) then continue for longstring clear r_buff%() web tcp read req%, r_buff%() ' now process the data and always make some response web transmit [PAGE/FILE/CODE] req%, ........ next req% end sub I will probably create a dedicated TCP function to replace the mm.info calls is a subsequent release My working test program is below. Not the use of the parsehtmldata$ function to understand the incoming request. This is now completely sorted for the PicoMiteWeb and makes it very easy to understand and respond to the incoming request. To complicate things the example can display and interact with the thermostat page as below and also the original test with the image of the tiger Option explicit Option default integer Dim myfloat!=16.123 Dim myint%=999 Dim mystring$="The PicoMite Web is GO!!!" Dim buff%(512) Dim pp$="INDEX" Const maxargs=20 Const ds18B20pin = 4 Const relaypin = 2 Const stemp=17 'setting for lowest temperature on radio buttons Const heatingoff$=" BGCOLOR='#00ff00'>Off" Const heatingon$=" BGCOLOR='#ff0000'>On " Const check$="checked='checked' " Const hysteresis=0.5 ' Dim checked$(11) Dim integer setpointb=4 'setting for default temperature Dim integer setpointt=stemp+setpointb-1 Dim notstarted=1,notended=0 Dim float currenttemp,readtemp Dim float maxtemp, mintemp Dim heating$=heatingon$ checked$(setpointb)=check$ SetPin relaypin,dout currenttemp=TEMPR(ds18b20pin) maxtemp=currenttemp mintemp=currenttemp updateheater On error skip WEB ntp WEB tcp interrupt TCPrequest Do If Right$(Time$,1)="0" And notstarted=1 Then TEMPR START ds18b20pin,3 notstarted=0 notended=1 EndIf If Right$(Time$,1)="2" And notended=1 Then readtemp=TEMPR(ds18b20pin) If readtemp<1000 Then currenttemp=readtemp notstarted=1 notended=0 maxmin updateheater EndIf ' poll Loop Sub TCPrequest Local a%,s$,page$,i,nparams% Local arg$(1,maxargs-1) For a%=1 To MM.Info(max connections) If Not MM.Info(TCP request a%) Then Continue For LongString clear buff%() WEB tcp read a%,buff%() If LLen(buff%()) Then ' Print "Received ",LLen(buff%())," bytes on PCB ",a%-1 ' LongString print buff%() page$=parsehtmldata$(nparams%,buff%(), arg$()) Print page$ For i=0 To nparams% Print arg$(0,i),"=",arg$(1,i) If arg$(0,i)="RB" Then ' setting for radio button checked$(setpointb)="" Print Val(Right$(arg$(1,i),Len(arg$(1,i))-1)) setpointb=Val(Right$(arg$(1,i),Len(arg$(1,i))-1)) setpointt=setpointb+stemp-1 checked$(setpointb)=check$ updateheater EndIf If arg$(0,i)="RESET" And arg$(1,i)="YES" Then 'Reset maxmin maxtemp=currenttemp mintemp=currenttemp EndIf Next If UCase$(page$)="INDEX" Then Print "sending test page" pp$=page$ WEB transmit page a%,"test4.html" ElseIf UCase$(page$)="THERMO" Then Print "sending thermostat page" pp$=page$ WEB transmit page a%,"thermo.html" ElseIf page$="small.jpg" Then Print "Sending picture" WEB transmit file a%,"small.jpg","image/jpeg" ElseIf page$="favicon.ico" Then Print "sending favicon" WEB Transmit FILE a%,"favicon.ico","image/vnd.microsoft.icon" Else s$=LGetStr$(buff%(),1,Min(255,LLen(buff%()))) Print s$ WEB transmit code a%, 404 EndIf EndIf Next a% End Sub ' Function parsehtmldata$(paramcount As integer, inbuf() As integer, arg$()) Const starttext$="HTTP" Local a$,b$ Local integer buf(Bound(inbuf())) Local integer inpos,startparam,processargs paramcount=0 inpos=LInStr(inbuf(),"GET /",1) If inpos=0 Then parsehtmldata$="" Else LongString MId buf(),inbuf(),inpos+5 inpos=LInStr(buf(),starttext$,1) If inpos>2 Then 'page request found inpos=inpos-2 a$=LGetStr$(buf(),1,inPos) inpos=Instr(a$,"?") If inpos<>0 Then 'parameters found processargs=1 parsehtmldata$=Left$(a$,inpos-1) a$=Mid$(a$,inpos+1) Do arg$(0,paramcount)="" arg$(1,paramcount)="" inpos=Instr(a$,"=") startparam=1 arg$(0,paramcount)=Mid$(a$,startparam,inpos-startparam) startparam=inpos+1 inpos=Instr(a$,"&") If inpos<>0 Then arg$(1,paramcount)=Mid$(a$,startparam,inpos-startparam) a$=Mid$(a$,inpos+1) paramcount=paramcount+1 Else arg$(1,paramcount)=Mid$(a$,startparam) paramcount=paramcount+1 processargs=0 EndIf Loop While processargs Else parsehtmldata$=a$ EndIf Else ' no page requested parsehtmldata$="INDEX" EndIf EndIf End Function Sub maxmin If currenttemp>maxtemp Then maxtemp=currenttemp EndIf If currenttemp<mintemp Then mintemp=currenttemp EndIf End Sub Sub updateheater ' Print "current setpoint is ",setpointt ' Print "current temperature is ",currenttemp Local float hcalc If setpointt=stemp+11 Then Pin(relaypin)=1 heating$=heatingon$ ElseIf setpointt=stemp Then Pin(relaypin)=0 heating$=heatingoff$ Else hcalc = setpointt + hysteresis If currenttemp>=hcalc Then 'turn heating off Pin(relaypin)=0 heating$=heatingoff$ EndIf hcalc = setpointt - hysteresis If currenttemp<=hcalc Then 'turn heating on Pin(relaypin)=1 heating$=heatingon$ EndIf EndIf End Sub ![]() |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3312 |
Thanks, Jim. I was using that formula, except what I found on the web was "+1" instead of "+3". "+4" is what actually works for me right now at this time (but my array of days of the week starts at index 1, not index 0). Next time I'll try to remember to use your mid$ function instead. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3312 |
Thanks, Peter--interrupt method working for me. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
Michal Senior Member ![]() Joined: 02/02/2022 Location: PolandPosts: 125 |
Hi @matherp Version PicoMiteWebV5.07.07a6.uf2(1 630 208B) is twice as slow as the previous one PicoMiteWeb.uf2(1 634 304B) in the test: Print "START" Dim INTEGER i T1=Timer For i=1 To 10000: Next T2=TIMER Print "Time PicoMite MMBASIC=";T2-T1;" msec" And in the current versions of PicoMite and PicoMiteVGA Michał |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10068 |
That's because the web interface is now working in polling mode rather than H/W interrupt mode. This is required if DS18B20 et. are to usable. I can probably reduce the polling rate but at the moment I'm more concerned about stability than speed |
||||
Michal Senior Member ![]() Joined: 02/02/2022 Location: PolandPosts: 125 |
Hi @matherp I don't know much, but maybe you could use a second core? Michal |
||||
pwillard Guru ![]() Joined: 07/06/2022 Location: United StatesPosts: 307 |
Appreciated. |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10068 |
V5.07.07a7 PicoMiteWebV5.07.07a7.zip More work on stability. One of the big issues was requests made to the server when no program was running. This version addresses that by sending code 404 if there is no program running. It is still up to you to handle all requests in a running program but this seems to improve things at the command prompt when the browser requests something when it shouldn't. Other general changes: AUTOSAVE APPEND Does what it says and appends the incoming data stream to an existing program. This can be very useful for adding library subroutines into a program without needing MMEdit or similar At the command prompt ONLY you can now use A: or B: to switch disk as well as DRIVE "A:" and DRIVE "B:" |
||||
homa![]() Guru ![]() Joined: 05/11/2021 Location: GermanyPosts: 459 |
Hi Peter, how do I reach the LED on the Pico W in mmbasic? I found this explanation of the difference between the two models on the net. ![]() greets Matthias |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10068 |
You can't. It is connected to a pin on the CYW43. |
||||
homa![]() Guru ![]() Joined: 05/11/2021 Location: GermanyPosts: 459 |
> option heartbeat off Error : Pin 43/Cannot find label is reserved > option heartbeat on Error : Pin 43/Cannot find label is reserved > that's what I suspected, my question is also are you planning a solution for this? Apparently the SDK provides other aliases for the pins. It would be nice to make SETPIN WGP0, DOUT | HEARTBEAT or so out of SETPIN GP25, DOUT | HEARTBEAT. Similar to the table. Edited 2023-02-10 04:17 by homa |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1965 |
I'm at my wits end, i just can't load the files into the file system. I asked on the other thread for some one to hold my hand and walk me through it and Peter replied . This is all new to me, can some one show me step by step how to do this. I have saved the files to a folder, and using TERATERM tried to use XMODEM RECEIVE it takes me to the folder I click on the file 'favicon for eg.' but nothing happens. Edit. Don't know why it has formatted like this. Edited 2023-02-10 07:28 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6220 |
My biased opinion is the simplest way is to use the file manager in MMEdit. With Teraterm. At the picomite command prompt XMODEM r "A:/filename" In Teraterm file menu ![]() You need File / Transfer / XModem / Send.. That will allow you to browse to the file. Sit back and wait. Do the same for every file you want to send to the picomite. Edit: I think you have 30 seconds (or is it 15) from when you enter the command in the pico to when teraterm has to start sending. Jim Edited 2023-02-10 07:46 by TassyJim VK7JH MMedit |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2417 |
Using TERATERM use XMODEM SEND to connect to XMODEM r[receive] "A:/filename" on the Pico. Edit. Start Xmodem on the Pico first, then in TeraTerm. The Pico times out if you take too long in TeraTerm selecting the folder & file. Edited 2023-02-10 07:53 by phil99 |
||||
homa![]() Guru ![]() Joined: 05/11/2021 Location: GermanyPosts: 459 |
Hi palcal, I want to try: To transfer a program from the program memory: First in the PiPico XMODEM SEND then in the menu of Tera Term RECEIVE and specify the location on the PC. Back first XMODEM RECEIVE in the PiPico and then in the menu of Tera Term SEND and select the file to send on the PC. Caution. The memory will be overwritten! If you want to transfer a file directly on the flash memory of the PiPico from the PC then: XMODEM RECEIVE "index.html". and then in the menu of Tera Term SEND and select the file to send from the PC (most names are the same "index.html", but can also be completely different). Note: The program memory remains untouched. Matthias Edited 2023-02-10 07:50 by homa |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3312 |
After xmodem r "filename" at the ">" prompt on the PicoMiteWeb, I click on "File" (on the Teraterm menu), Transfer, XMODEM, SEND, then navigate to the folder on your PC and doubleclick the file. The Picomite name of the file does not have to match the filename on the PC. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1965 |
OK got that done OK, but I dont get much when I run it, just the time. Do I have to port forwward 80 and access it from a browser ? I'm lost. Maybe this is too much for me, a bit over my head. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7513 |
I still get confused by all this too. I have to look up the xmodem command every time I need it. And that's without messing about with a -w board. lol Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3312 |
Do I have to port forward 80 and access it from a browser ? I'm lost. Maybe this is too much for me, a bit over my head. If everything succeeded and "files" shows you the files you need, all you need to do is note which IP was reported when you powered up and then in your browser, enter the ip, e.g., 192.168.1.224. These are my options: OPTION COLOURCODE ON OPTION DISPLAY 40, 110 OPTION TCP SERVER PORT 80 OPTION WIFI SomeAP, SomePW After the xmodem R for your .bas file, you will need to LOAD or EDIT it, and then RUN it. ~ Edited 2023-02-10 08:44 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1965 |
That is what I am doing, I have it running in TERATERM and when I try to connect to 10.0.0.43 teraterm gives me sending page and the browser tells me... This 10.0.0.43 page can’t be found Edited 2023-02-10 09:03 by palcal "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |