Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 23:27 29 Mar 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 : Webmite V5.07.08 betas : UDP and other stuff

     Page 1 of 5    
Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8517
Posted: 10:59am 29 May 2023
Copy link to clipboard 
Print this post

V5.07.08b0


WebMiteV5.07.08b0.zip


This version fixes a bug where a TCP request while in the editor (or autosave) caused the Webmite to crash

New functionality

WEB TCP SEND cb%, data%()
WEB TCP CLOSE cb%


These two commands allow more flexibility in using the TCP server. Unlike WEB TRANSMIT PAGE or WEB TRANSMIT FILE, WEB TCP SEND does not create any sort of header, nor does it close the TCP connection after transmission. It just sends exactly what is in the LONGSTRING data%() and it is up to the Basic programmer to close the connection when appropriate. An example of use is given below.

Dim q%(100),r%(100)
LongString append q%(),"HTTP/1.1 200 OK"+Chr$(13)+Chr$(10)
LongString append q%(),"Server:CPi"+Chr$(13)+Chr$(10)
LongString append q%(),"Connection:close"+Chr$(13)+Chr$(10)
LongString append q%(),"Content-type:text/html"+Chr$(13)+Chr$(10)
LongString append q%(),"Content-Length:80"+Chr$(13)+Chr$(10)+Chr$(13)+Chr$(10)
LongString append r%(),"<title>WebMite</title>"
LongString append r%(),"<h2>Temperature Monitor</h2>"
LongString append r%(),"The temperature is 0"+Chr$(13)+Chr$(10)
Dim buff%(4096/8)
WEB TCP INTERRUPT WebInterrupt
Do
'<do some processing here>'
Loop

Sub WebInterrupt
 Local a%, p%, t%, s$
 For a% = 1 To MM.Info(MAX CONNECTIONS)
   WEB TCP READ a%, buff%()
   p% = LInStr(buff%(),"GET")
   t% = LInStr(buff%(),"HTTP")
   If (p% <> 0) And (t% > p%) Then
     LongString print q%()
     WEB TCP SEND a%,q%()
     WEB TCP SEND a%,r%()
     WEB TCP CLOSE a%
   Else
     WEB transmit code a%,404
   EndIf
 Next a%
End Sub


The second functional enhancement implements a simple way of communicating over UDP

The new commands are:

OPTION UDP SERVER PORT n
WEB UDP INTERRUPT intname
WEB UDP SEND addr$, port, data$


OPTION UDP SERVER PORT sets up a listening socket on the port specified. Any UDP datagrams received on that port will be processed and the contents saved in MM.MESSAGE$. The IP address of the sender will be stored in MM.ADDRESS$. Note: If the UDP datagram is longer than 255 characters then any extra is discarded.

WEB UDP INTERRUPT sets up a BASIC interrupt routine that will be triggered whenever a UDP datagram is received

WEB UDP SEND is used to send a datagram to a remote receiver. In this case the IP address must be specified and can be either a numeric address (e.g. "192.168.1.147") or a normal text address (e.g. "google.com"). The port number of the receiver must also be specified and, of course, the message itself. The SEND command can be used as a response to an incoming message or stand-alone.

e.g.

WEB udp interrupt myint
WEB udp send "192.168.1.155",77,"starting udp echo"
Do
Loop
Sub myint
Print "received "+mm.message$+" from "+mm.address$
WEB udp send mm.address$,77,mm.message$
End Sub






Edited 2023-05-29 21:20 by matherp
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3423
Posted: 11:31am 29 May 2023
Copy link to clipboard 
Print this post

Thanks for fixing the editor.

To UDP: please confirm. The server listens only to the port set in OPTION, but you can send to any port?

Volhout

P.S. dit you see any solution to logging in in an open wifi network (no security (no WPA/WPA2/WEP, no password required).
Edited 2023-05-29 22:01 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3423
Posted: 12:20pm 29 May 2023
Copy link to clipboard 
Print this post

@Peter,

What is the intended way to implement correct daylight savings time (UTP->DST)?
IS there anything in the NTP we can use, or do we write a algorithm in MMBasic (could be stored in the library ?).

Volhout
Edited 2023-05-29 22:22 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 500
Posted: 12:21pm 29 May 2023
Copy link to clipboard 
Print this post

Thanks a lot Matherp  
Plasma
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3423
Posted: 12:22pm 29 May 2023
Copy link to clipboard 
Print this post

deleted..duplicate
Edited 2023-05-29 22:35 by Volhout
PicomiteVGA PETSCII ROBOTS
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8517
Posted: 12:33pm 29 May 2023
Copy link to clipboard 
Print this post

  Quote  The server listens only to the port set in OPTION, but you can send to any port?


Yes

  Quote   Also broadcast ? 255.


Don't know but probably not.

  Quote  What is the intended way to implement correct daylight savings time (UTC->DST)?
IS there anything in the NTP we can use, or do we write a algorithm in MMBasic (could be stored in the library ?).


You will need to write something in Basic - Geoff has this code in his super-clock program
Edited 2023-05-29 22:35 by matherp
 
ville56
Regular Member

Joined: 08/06/2022
Location: Austria
Posts: 68
Posted: 02:09pm 29 May 2023
Copy link to clipboard 
Print this post

Peter, thanks for implementing UDP but i can't get V5.07.08b0 running stable. Even cleared flash with clear_flash.uf2 but this version shows strange behavior.

- If no OPTION WIFI set, there seems to be no problem. Just tested on commandline.
- Having WIFI set to connect to my LAN and if the connection is unsuccessful (Fritz!Box), as on every second try, there seems to be no problem either.
- If successfully connected to LAN then after entering a few chars at the console input, the pico hangs. Even the heartbeat led stops blinking. It is not possible to connect via telnet, even immediately after restart. Only OPTION WIFI was set. Hardware is geniue Pico with V5.07.07 running like a charm.

Regards,
Gerald
                                                                 
73 de OE1HGA, Gerald
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3163
Posted: 02:18pm 29 May 2023
Copy link to clipboard 
Print this post

  Volhout said  What is the intended way to implement correct daylight savings time (UTP->DST)?
IS there anything in the NTP we can use, or do we write a algorithm in MMBasic (could be stored in the library ?).

When you get the weather for a city from Open Weather Map they will also give you the time zone which includes an adjustment for DST.

This example is for Paris (untested but should work):

CONST Key = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn"
CONST Query = "GET /data/2.5/weather?q=Paris,fra&APPID="+Key+Chr$(10)+Chr$(13)
DIM buff%(4096/8)

WEB OPEN TCP CLIENT "api.openweathermap.org", 80
WEB TCP CLIENT REQUEST Query, buff%()
WEB CLOSE TCP CLIENT
i = val(JSON$(b(), "timezone"))
PRINT "The timezone for Paris (incl DST) is:" i/3600
WEN NTP i/3600

Geoff
Edited 2023-05-30 00:24 by Geoffg
Geoff Graham - http://geoffg.net
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8517
Posted: 03:47pm 29 May 2023
Copy link to clipboard 
Print this post

  Quote  Peter, thanks for implementing UDP but i can't get V5.07.08b0 running stable. Even cleared flash with clear_flash.uf2 but this version shows strange behaviour.


Strange as it obviously worked for me.
I've done a complete re-compile and this version will force an option reset. let me know if this fixes the issue.
This version should also work both sending and receiving broadcast UDP packets


WebMiteV5.07.08b1.zip


Couple of typos in Geoff's code but with these fixed it works a treat as mm.startup in the library

Sub mm.startup
Const Key = "nnnnnnnnnnnnnnnnnnnnnnn"
Const Query = "GET /data/2.5/weather?q=Paris,fra&APPID="+Key+Chr$(10)+Chr$(13)
Dim buff%(4096/8)
WEB OPEN TCP CLIENT "api.openweathermap.org", 80
WEB TCP CLIENT REQUEST Query, buff%()
WEB CLOSE TCP CLIENT
i = Val(Json$(buff%(), "timezone"))
WEB NTP i/3600
End Sub

Edited 2023-05-30 02:30 by matherp
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 500
Posted: 04:15pm 29 May 2023
Copy link to clipboard 
Print this post

V5.07.08b0 first version - same problems as ville56
V5.07.08b0 second version - looks like it works , i test the new commands

can we get tcp and udp server at the same time ?
Plasma
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8517
Posted: 04:31pm 29 May 2023
Copy link to clipboard 
Print this post

  Quote  can we get tcp and udp server at the same time ?


TCP server, udp server, tftp server, and telnet server all at the same time

Note I've updated the above post to b1
Edited 2023-05-30 02:32 by matherp
 
ville56
Regular Member

Joined: 08/06/2022
Location: Austria
Posts: 68
Posted: 04:32pm 29 May 2023
Copy link to clipboard 
Print this post

Peter, the last version from your post seems to have fixed the problem.

many thanks,
Gerald
                                                                 
73 de OE1HGA, Gerald
 
hhtg1968
Senior Member

Joined: 25/05/2023
Location: Germany
Posts: 113
Posted: 05:10pm 29 May 2023
Copy link to clipboard 
Print this post

many thanx to matherp. the bug in the editor is solved!
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 2989
Posted: 06:50pm 29 May 2023
Copy link to clipboard 
Print this post

Very happy to see UDP. What a powerful little device the Pico W is running MMBasic.

Thanks for all your fine work.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 07:06pm 29 May 2023
Copy link to clipboard 
Print this post

  Volhout said  ... DST ...


http://www.fruitoftheshed.com/MMBasic.Function-to-Test-a-DateTime-to-see-if-Daylight-Savings-should-be-applied.ashx
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8517
Posted: 08:40pm 29 May 2023
Copy link to clipboard 
Print this post

Doesn't work for southern hemisphere unless I'm missing something whereas Geoff's idea is universal for the Pico-W
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3423
Posted: 08:42pm 29 May 2023
Copy link to clipboard 
Print this post

Thanks captain!

I almost forgot about the integer divide, thanks to your example this came back to mind....

Going to use this in a library...

Volhout
PicomiteVGA PETSCII ROBOTS
 
Andrew_G
Guru

Joined: 18/10/2016
Location: Australia
Posts: 839
Posted: 10:07pm 29 May 2023
Copy link to clipboard 
Print this post

Hi all,
This thread doctored Captain's code for the Southern Hemisphere for non-WebMites.
Geoff's code using Openweather now works for me and is far simpler.

Cheers,

Andrew
 
andreas

Senior Member

Joined: 07/12/2020
Location: Germany
Posts: 187
Posted: 11:00am 30 May 2023
Copy link to clipboard 
Print this post

Is there a possible memory leak or why is "General" memory increasing?

I have tested this program on a pico w (5.07.08b1) to measure brightness sensor on gp28 and send the values to a MQTT broker. With each turn the "General" RAM is increasing upto a "out of memory error" after a while of measurements:

> list
SetPin gp28, ain

Do
 helligkeit = Pin(gp28)
 Print "Helligkeit: ";helligkeit
 On ERROR SKIP
 WEB MQTT CONNECT "192.168.178.54",1883,"anon", "anon"
 If Not MM.Errno Then
   WEB MQTT PUBLISH "brightness",Str$(helligkeit,3,2)
   WEB MQTT CLOSE
 EndIf
 Pause 1000
 Memory
Loop


(..some loops..)
Helligkeit:  2.876385836
Program:
  1K ( 1%) Program (14 lines)
 79K (99%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 1%) 1 Variable
 79K (73%) General
 26K (26%) Free
Helligkeit:  2.878669109
Program:
  1K ( 1%) Program (14 lines)
 79K (99%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 1%) 1 Variable
 79K (74%) General
 26K (25%) Free
Helligkeit:  2.877728938
Program:
  1K ( 1%) Program (14 lines)
 79K (99%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 1%) 1 Variable
 80K (74%) General
 25K (25%) Free
Helligkeit:  2.88041514
Program:
  1K ( 1%) Program (14 lines)
 79K (99%) Free

Library:
  1K ( 1%) Library
 79K (99%) Free

Saved Variables:
 16K (100%) Free

RAM:
  1K ( 1%) 1 Variable
 80K (75%) General
 25K (24%) Free
[4] helligkeit = Pin(gp28)
Error : Not enough memory


> option list
WebMite MMBasic Version 5.07.08b1
OPTION SYSTEM I2C GP0,GP1
OPTION AUTORUN ON
OPTION LIBRARY_FLASH_SIZE  14000
OPTION COLOURCODE ON
OPTION DISPLAY 50, 100
OPTION WIFI FritzBox, *********************
OPTION TELNET CONSOLE ON
OPTION SDCARD GP5, GP2, GP3, GP4

-andreas
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 3423
Posted: 12:14pm 30 May 2023
Copy link to clipboard 
Print this post

Hi Andreas,

What is OPTION LIBRARY_FLASH_SIZE 14000 ????
This is not listed in the user manual...
I thought the library was fixed size (1 flash slot)

Volhout
Edited 2023-05-30 22:15 by Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 1 of 5    
Print this page
© JAQ Software 2024