Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 20:33 26 Apr 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 1 of 8    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 06:42pm 06 Feb 2023
Copy link to clipboard 
Print this post

For those not following the other thread, I have ported the PicoMite firmware to the Pico W





This variant has all of the functionality of the standard PicoMite with the exception of the GUI commands and function. These have made way for the WEB command that allows wireless access to the internet and the json function has also been added to allow you to parse the data from things like openweathermap.org.

No extra hardware is needed to work as a web server and/or web client.

The latest alpha release is V5.07.07a3

PicoMiteWeb.zip

The code is still alpha so expects lockups and resets and make sure you back up programs to the flash disk, flash slots, or an SDcard (NTP seems to be a particular culprit for lockups). Alternatively do your development in MMEDIT and that way you will never lose anything.

To install the firmware just copy the uf2 file to a Pico W in boot mode as normal.

To connect to your WiFi router use the command

OPTION WIFI ssid$, password$


e.g. OPTION WIFI "myssid","myduffpassword"

The Pico will reboot and you should see it report connection and its IP address.
You can now use a range of commands to access the network

First it is worth executing:
WEB NTP [timeoffset]

This connects to an NTP server and automatically sets the time and date in the Picomite. The offset is the time in hours that your timezone differs from UTC.
e.g. WEB NTP -5
for east coast America and Canada.

Currently the firmware supports working as either a TCP SERVER and/or a TCP CLIENT
To set the Pico W up as a TCP SERVER (i.e. able to host a simple website) use the command

OPTION TCP SERVER PORT n

e.g OPTION TCP SERVER PORT 80

Again the Pico W will reboot and will report both the connection to the WiFi router and that a TCP server is now running



All the information you need to set up a simple web site and details of the commands are in this thread
and I attach my example files here

simpleweb.zip





Today's new functionality supports TCP client mode.
This allows you do talk to a TCP server (obviously   )

The command
WEB OPEN TCP CLIENT address$, port

opens the client and connects to the web address specified. The web address can either be a URL e.g. "api.openweathermap.org" or an IP address e.g. "192.168.1.111"

Then we can use the command
WEB TCP CLIENT REQUEST request$, buff%() [,timeout]

to send a request to the remote server and wait for an answer. The optional timeout parameter is in milli-seconds and defaults to 5000.  buff%() is an integer array which will receive the response as a LONGSTRING
e.g.
WEB TCP CLIENT REQUEST "GET /data/2.5/weather?q=Saffron Walden,uk&APPID=xxxxxxxxxxxxxxxxx"+chr$(10)+chr$(13)

If the request times out you will get an error. Otherwise the received data is in the LONGSTRING
If the received data is a json string then you can use the JSON$ function to parse it
JSON$(array%(),string$)

Returns a string representing a specific item out of the JSON input stored in the longstring array%()
e.g.
JSON$(a%(), “name”)
JSON$(a%(), “coord.lat”)
JSON$(a%(), “weather[0].description”)
JSON$(a%(),”list[4].weather[0].description
Examples taken from api.openweathermap.org

Having received data from the client it is normally the case that you want to close the client connection using
WEB CLOSE TCP CLIENT


At the moment only one client connection is allowed

A full example application is given below - pretty simple. Note if you have used openweathermap before they have changed the interface and you may need to sign up for a new (free) account to get your APPID .

Dim buff%(512)
Dim APIKEY$="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
WEB ntp
Dim report$="weather?q=Saffron Walden,uk"
Dim b$= "GET /data/2.5/"+report$+"&APPID="+APIKEY$+Chr$(10)+Chr$(13)
WEB open tcp client "api.openweathermap.org",80
WEB TCP CLIENT REQUEST b$,buff%(),10000
WEB close tcp client
Print "Weather for " + Json$(buff%(),"name")
Print "Temperature is ",Val(Json$(buff%(),"main.temp"))-273
Print "Pressure is ",Json$(buff%(),"main.pressure")
Print Json$(buff%(),"weather[0].description")




Edited 2023-02-07 04:44 by matherp
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 07:29pm 06 Feb 2023
Copy link to clipboard 
Print this post

Great progress.

I'll find out soon enough, but if flashing over the previous PicoMiteWeb alpha firmware, are OPTIONS lost? Or files in the flash disk?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3657
Posted: 07:32pm 06 Feb 2023
Copy link to clipboard 
Print this post

That's looking good.

Maybe change such as

WEB open tcp client "api.openweathermap.org",80
WEB TCP CLIENT REQUEST b$,buff%(),10000

to

WEB open http client "api.openweathermap.org",80
WEB HTTP CLIENT REQUEST b$,buff%(),10000

That way you can do HTTPS one day and other than HTTP at some point if desired.

John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5903
Posted: 08:13pm 06 Feb 2023
Copy link to clipboard 
Print this post

  lizby said  Great progress.

I'll find out soon enough, but if flashing over the previous PicoMiteWeb alpha firmware, are OPTIONS lost? Or files in the flash disk?


You will have to list the options and save the list yourself but MMEdit's file manager works happily with the PicoW so it is simple to backup your files to PC. It is always worth keeping a copy on PC with the flash drive, especially during alpha and beta stages.

Jim
VK7JH
MMedit   MMBasic Help
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5903
Posted: 08:17pm 06 Feb 2023
Copy link to clipboard 
Print this post

Yesterday's firmware was still running happily this morning so stability looks good.
With the new alpha, I should be ably to get two picoWs talking to each other. I just need to order that second module.

Jim
VK7JH
MMedit   MMBasic Help
 
homa

Senior Member

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


Hello Peter,

I am still with the V5.07.07a2
Does the version a3 also delete the flash drive again?

Thanks for the output of the assigned IP from DHCP when connecting.
Is from you planned that there will be also a possibility to predefine the IP? (e.g. OPTION WIFI myssid$,mypwd$,myIP$)

Could you also output the queried IP during the NTP query if you specify an offset?

> web ntp
ntp address 167.235.156.255
got ntp response: 06/02/2023 21:07:39
> web ntp +1
got ntp response: 06/02/2023 22:07:45
>

Here it would also be great if you could specify your own/different NTP server to query. Then you don't have to leave your own network.
WEB NTP [timeoffset] myNTPip$ -> WEB NTP +1 "192.168.1.1" or WEB NTP +1 "0.de.pool.ntp.org"

Otherwise I think the TCP server is great!

The TCP Client also looks promising! I will test it ... the weekend is coming :-)

Many greetings
Matthias
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 10:55pm 06 Feb 2023
Copy link to clipboard 
Print this post

With a structure like the following, why am I getting a timeout?

initial:
 Dim buff%(512)
 WEB ntp -5
 initialize
 
main:
 do
   watchdog 60000 ' lb if not executed in 60 seconds, restart
   if sMinuteDigit <> mid$(time$,5,1) then newMinute
   if SIMULATE then poll
'    GetUserInputs  ' get inputs from local display
'    ReadSensors    ' get temperature and humidity
'    DisplayData
 loop

Sub poll
Local p%, t%, ii%, ss$
For ii%=1 To mm.info(max connections)
  LongString clear buff%()
  WEB tcp read ii%,buff%()
  p%=LInStr(buff%(),"GET")
  t%=LInStr(buff%(),"HTTP")
  If LLen(buff%()) Then Print "_________________________________________________"
  ss$=""
  If (p%<>0) And  (t%<>0) And (t%>p%) Then
    ss$=LGetStr$(buff%(),p%,t%-p%+4)
    Print "String is ",ss$
  EndIf
  If Instr(ss$,"small") Then
    Print "sending picture"
    WEB Transmit FILE ii%,"small.jpg","image/jpeg"
  ElseIf Instr(ss$,"favicon") Then
    Print "sending icon"
    WEB Transmit FILE ii%,"favicon.ico","image/vnd.microsoft.icon"
  ElseIf Instr(ss$,"HTTP") Then
    Print "sending page"
    WEB transmit page ii%,"gh.html" ' "gh.html"
  EndIf
Next ii%
End Sub

After some initialization, my main loop calls "poll". That successfully sends my page when I make the request in the browser. When I enter data and press the <Submit> button, my GET request is shown with "Print "String is ...". Then after a minute it times out. I had assumed that it would quickly do the 4 loops in "poll" and return to the main loop with the WATCHDOG 60000 statement.

What am I doing wrong with this structure?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 03:02am 07 Feb 2023
Copy link to clipboard 
Print this post

  lizby said  I'll find out soon enough, but if flashing over the previous PicoMiteWeb alpha firmware, are OPTIONS lost? Or files in the flash disk?


And the answer is: OPTIONS persist, files are not lost.

Making some progress:



I'm not getting values returned when I check a box and enter a value and press [Simulate].  After a minute, I get a watchdog timeout. Some minutes later I get this on the browser line: http://192.168.1.224/G?Y=0&W=2&W=5&A=&B=&C=74&D=&E=&F=

(Which is expected.)

I'll try again removing the watchdog command.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
homa

Senior Member

Joined: 05/11/2021
Location: Germany
Posts: 238
Posted: 06:24am 07 Feb 2023
Copy link to clipboard 
Print this post


  lizby said  
And the answer is: OPTIONS persist, files are not lost.

Thank you!

  homa said  
Thanks for the output of the assigned IP from DHCP when connecting.
Is from you planned that there will be also a possibility to predefine the IP? (e.g. OPTION WIFI myssid$,mypwd$,myIP$)


Good morning Peter,
sometimes you should sleep on it first ...
It needs of course then also the gateway and the netmask.

(e.g. OPTION WIFI mySsid$,myPwd$,myIP$,NetMask$,Gateway$)

A lot of work, but very cool!
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5903
Posted: 06:44am 07 Feb 2023
Copy link to clipboard 
Print this post

@homa,
While lizby and I both had options and files etc retained with the flashing new firmware 'this time', you should not expect to have the same success. There might be a setting in OPTIONs that causes your system to loose it all.

If you want a fixed IP on your WIFI, it is usually better to tell the accesspoint/router to assign the fixed address instead of trying to do it yourself.

I think you will find that the WEB NTP command will show you the server IP again if you wait long enough between calls.
It does for me with my time-zone included.

Jim
VK7JH
MMedit   MMBasic Help
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 08:24am 07 Feb 2023
Copy link to clipboard 
Print this post

lizby

poll must be called repeatedly and should not be contingent on anything. It is completely benign if no communication has occurred
 
pwillard
Senior Member

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

Man, this is really great, I really appreciate it.

I initially had some time-out issues... but ultimately it started working after a hard reboot.
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 01:21pm 07 Feb 2023
Copy link to clipboard 
Print this post

a4


PicoMiteWebV5.07.07a4.zip

Fixes a bug in SETPIN and includes support for Waveshare 1.44" display ST7735S
 
Amnesie
Guru

Joined: 30/06/2020
Location: Germany
Posts: 381
Posted: 05:17pm 07 Feb 2023
Copy link to clipboard 
Print this post

Hello,

wonderful news, but can I replace the normal Pico with the Wifi-version (since they seem to be pin compatible) in my pico VGA board? Or will there be a new PCB? I've read so far that only "internal" (?) pins on the Pico are used, so I can just drop in the new Pico-W version and I am good to go?

Greetings
Daniel
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 05:30pm 07 Feb 2023
Copy link to clipboard 
Print this post

  Quote  but can I replace the normal Pico with the Wifi-version (since they seem to be pin compatible) in my pico VGA board?


The PicoMiteWeb is a variant of the PicoMite, not the VGA version - that would use too much memory to be properly useful even if there wasn't bus contention
The memory issue is also why I removed the GUI command from the PicoMite to make the web version
Edited 2023-02-08 03:46 by matherp
 
homa

Senior Member

Joined: 05/11/2021
Location: Germany
Posts: 238
Posted: 05:52pm 07 Feb 2023
Copy link to clipboard 
Print this post

  TassyJim said  @homa,
While lizby and I both had options and files etc retained with the flashing new firmware 'this time', you should not expect to have the same success. There might be a setting in OPTIONs that causes your system to loose it all.


@Jim: Thanks for pointing that out, but I didn't have any problems either. I am now on version a4.

  TassyJim said  
If you want a fixed IP on your WIFI, it is usually better to tell the accesspoint/router to assign the fixed address instead of trying to do it yourself.

Yes, if there is a DHCP in this network ;-)

@Peter:
What about the possibility to create your own AP with wifi and ssid over the pico? This is not to create pressure with you now please! Is just an idea of the possibilities of what all could be done with the Pico W and MMbasic projects.

  TassyJim said  
I think you will find that the WEB NTP command will show you the server IP again if you wait long enough between calls.
It does for me with my time-zone included.

This makes no sense to me, there should always be the same output on a command ...
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 06:01pm 07 Feb 2023
Copy link to clipboard 
Print this post

  Quote  This makes no sense to me, there should always be the same output on a command ...


The output depends on whether LWIP has cached the address and whether it subsequently times out the cache
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3015
Posted: 06:43pm 07 Feb 2023
Copy link to clipboard 
Print this post

I'm still stuck. I changed the original webserver.bas program to serve my html page, gh1.html:

Dim buff%(512)
Dim myfloat!=16.123
Dim myint%=999
Dim mystring$="The PicoMite Web is GO!!!"
WEB ntp -5
Do
poll
Loop
'
Sub poll
Local p%, t%
For a%=1 To MM.Info(max connections)
LongString clear buff%()
WEB tcp read a%,buff%()
p%=LInStr(buff%(),"GET")
t%=LInStr(buff%(),"HTTP")
If LLen(buff%()) Then Print "_________________________________________________"
s$=""
If (p%<>0) And  (t%<>0) And (t%>p%) Then
  s$=LGetStr$(buff%(),p%,t%-p%+4)
  Print "String is ",s$
EndIf
If Instr(s$,"small") Then
  Print "sending picture"
  WEB Transmit FILE a%,"small.jpg","image/jpeg"
ElseIf Instr(s$,"favicon") Then
  Print "sending icon"
  WEB Transmit FILE a%,"favicon.ico","image/vnd.microsoft.icon"
ElseIf Instr(s$,"HTTP") Then
  Print "sending page"
  WEB transmit page a%,"gh1.html" ' "test4.html"
EndIf
Next a%
End Sub

The page is served fine:



If I click the "LOUVER VENT" checkbox, put "74" in the "Outside Humidity" box, and press "Simulate", nothing happens for some time and then I get this:



There's never a response from the server, and MMBasic is locked up--I have to power cycle to get the ">" prompt. (In fact, the server is locked up immediately after it prints "sending page".)

Attached is the html file, "g1html.zip"--it contains gh1.html.

Any thoughts on what I should do?
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8579
Posted: 06:46pm 07 Feb 2023
Copy link to clipboard 
Print this post

I think I understand the issue but I'll start with a much simpler example and see what, if anything, needs to change
Edited 2023-02-08 04:50 by matherp
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 5903
Posted: 08:21pm 07 Feb 2023
Copy link to clipboard 
Print this post

  Quote  Attached is the html file, "g1html.zip"--it contains gh1.html.

I can't see the attachment.

What browser are you using?

If you print out the full packet sent by your broqwser, it migh thelp see what's happening.
If (p%<>0) And  (t%<>0) And (t%>p%) Then
   longstring print buff%()' add this line.


Jim
VK7JH
MMedit   MMBasic Help
 
     Page 1 of 8    
Print this page
© JAQ Software 2024