Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 11:34 07 May 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMiteWeb firmware for the Pico W - now making real progress

     Page 3 of 8    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8597
Posted: 08:47am 09 Feb 2023
Copy link to clipboard 
Print this post

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





  Quote  <html>
<head>
<title>
Remote Thermostat</title></head
<link rel="icon" type="image/x-icon" sizes="16x16" href="data:image/png;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAP//ADMA/wD/AAQAFf8AAAIACABZAP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAUAVQBVAAUABQUABQBQBVAFBQAFAFAFBQAAVQBVAAUFBQAAAAAABVAAAAAAAAAAAAAAAAAAACREMzERAAAAJkRDMxEQAAAmZEQzMREAAAZmREMzERAAAGZkRDMxEQAABmZEQzMREAAAZmREMzERAAAGZkRDMxH//wAAuzMAALrtAACa7QAArzMAAKv/AACf/wAA//8AAAA/AAAAHwAAAA8AAIAHAADAAwAA4AEAAPAAAAD4AAAA" />
<body>
<form name='f1' method='get' action='{pp$}'>
<h2 align='left'>Remote Thermostat Control System V1.0</h2>
Update Code: <input type='text' name='CODE' size='6' value='000000'><br><p><TABLE BORDER='1' CELLSPACING='0' CELLPADDING='5'>
<TR><TD>Heating</TD><TD{heating$}</TD></TR>
</TABLE></p><p><TABLE BORDER='1' CELLSPACING='0' CELLPADDING='5'><TR><TD></TD>
<TD>Temperature</TD></TR><TR><TD>Current</TD><TD> {str$(currenttemp,4,1)}°C<br></TD><TR><TD>Max</TD><TD> {str$(maxtemp,4,1)}°C<br></TD><TR>
<TD>Min</TD><TD> {str$(mintemp,4,1)}°C<br></TD>
</TABLE></p><input name='RESET' type='checkbox' value='YES' onClick='this.form.submit()'>
Reset Max/Min<p><TABLE BORDER='1' CELLSPACING='0' CELLPADDING='5'><TR><TD>Thermostat</TD>
<TD><input name='RB' type='radio' value='R0' {checked$(0)} onClick='this.form.submit()'> Off<br></TD>
<TD><input name='RB' type='radio' value='R1' {checked$(1)} onClick='this.form.submit()'> {stemp}<br></TD>
<TD><input name='RB' type='radio' value='R2' {checked$(2)} onClick='this.form.submit()'> {stemp+1}<br></TD>
<TD><input name='RB' type='radio' value='R3' {checked$(3)} onClick='this.form.submit()'> {stemp+2}<br></TD>
<TD><input name='RB' type='radio' value='R4' {checked$(4)} onClick='this.form.submit()'> {stemp+3}<br></TD>
<TD><input name='RB' type='radio' value='R5' {checked$(5)} onClick='this.form.submit()'> {stemp+4}<br></TD>
<TD><input name='RB' type='radio' value='R6' {checked$(6)} onClick='this.form.submit()'> {stemp+5}<br></TD>
<TD><input name='RB' type='radio' value='R7' {checked$(7)} onClick='this.form.submit()'> {stemp+6}<br></TD>
<TD><input name='RB' type='radio' value='R8' {checked$(8)} onClick='this.form.submit()'> {stemp+7}<br></TD>
<TD><input name='RB' type='radio' value='R9' {checked$(9)} onClick='this.form.submit()'> {stemp+8}<br></TD>
<TD><input name='RB' type='radio' value='R10' {checked$(10)} onClick='this.form.submit()'> {stemp+9}<br></TD>
<TD><input name='RB' type='radio' value='R11' {checked$(11)} onClick='this.form.submit()'> On<br></TD>
</TABLE>
</p></form>
</body></html>
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3019
Posted: 01:40pm 09 Feb 2023
Copy link to clipboard 
Print this post

  TassyJim said  For 'day of week" try ...


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 States
Posts: 3019
Posted: 01:59pm 09 Feb 2023
Copy link to clipboard 
Print this post

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: Poland
Posts: 116
Posted: 02:12pm 09 Feb 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 8597
Posted: 02:18pm 09 Feb 2023
Copy link to clipboard 
Print this post

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: Poland
Posts: 116
Posted: 02:37pm 09 Feb 2023
Copy link to clipboard 
Print this post

Hi @matherp

I don't know much, but maybe you could use a second core?

Michal
 
pwillard
Senior Member

Joined: 07/06/2022
Location: United States
Posts: 274
Posted: 02:41pm 09 Feb 2023
Copy link to clipboard 
Print this post

  Quote  I'm more concerned about stability than speed


Appreciated.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8597
Posted: 04:08pm 09 Feb 2023
Copy link to clipboard 
Print this post

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

Senior Member

Joined: 05/11/2021
Location: Germany
Posts: 245
Posted: 05:27pm 09 Feb 2023
Copy link to clipboard 
Print this post


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 Kingdom
Posts: 8597
Posted: 05:57pm 09 Feb 2023
Copy link to clipboard 
Print this post

You can't. It is connected to a pin on the CYW43.
 
homa

Senior Member

Joined: 05/11/2021
Location: Germany
Posts: 245
Posted: 06:16pm 09 Feb 2023
Copy link to clipboard 
Print this post


  matherp said  You can't. It is connected to a pin on the CYW43.



> 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: Australia
Posts: 1805
Posted: 09:26pm 09 Feb 2023
Copy link to clipboard 
Print this post

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
  Quote  XMODEM r "A:/filename"
.
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: Australia
Posts: 5915
Posted: 09:41pm 09 Feb 2023
Copy link to clipboard 
Print this post

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   MMBasic Help
 
phil99

Guru

Joined: 11/02/2018
Location: Australia
Posts: 1802
Posted: 09:47pm 09 Feb 2023
Copy link to clipboard 
Print this post

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

Senior Member

Joined: 05/11/2021
Location: Germany
Posts: 245
Posted: 09:48pm 09 Feb 2023
Copy link to clipboard 
Print this post

  palcal said  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
  Quote  XMODEM r "A:/filename"
.
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.


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 States
Posts: 3019
Posted: 09:49pm 09 Feb 2023
Copy link to clipboard 
Print this post

  palcal said  can some one show me step by step how to do this.


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: Australia
Posts: 1805
Posted: 10:29pm 09 Feb 2023
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 5742
Posted: 10:31pm 09 Feb 2023
Copy link to clipboard 
Print this post

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 States
Posts: 3019
Posted: 10:37pm 09 Feb 2023
Copy link to clipboard 
Print this post

  palcal said  OK got that done OK, but I dont get much when I run it, just the time.
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: Australia
Posts: 1805
Posted: 11:00pm 09 Feb 2023
Copy link to clipboard 
Print this post

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
  Quote  String is       GET / HTTP
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"
 
     Page 3 of 8    
Print this page
© JAQ Software 2024