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 alphas a19+: now with added jokes (i.e. HTTPS)
Page 1 of 2 | |||||
Author | Message | ||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9144 |
V5.07.07a19 PicoMiteWebV5.07.07a19.zip Dim buff%(512) Dim b$= "GET /random_joke" WEB open tls client "official-joke-api.appspot.com",443 WEB tls CLIENT REQUEST b$,buff%(),10000 WEB close tlS client a%=LInStr(buff%(),"{")-1 If a%<>-1 Then LongString trim buff%(),a% 'LongString print buff%() Print Json$(buff%(),"setup") Print Json$(buff%(),"punchline") EndIf I have now implemented TLS which is the technology behind making HTTPS requests. This is HEAVY needing > 32KB of C heap memory to handle the certification and encryption and has reduced the variable memory to 80Kb as well as slowing MMbasic by about 20%. However, I think this is pretty much essential as many websites now only respond on port 443 (TLS) so it is something we will have to live with to make the PicoMiteWEB properly useful. The PicoMiteWeb should therefore not be considered a general purpose port like the others but used only when you actually need web connectivity. One more point that needs understanding: The complexity of the web interfacing code means that it is unrealistic to handle all error conditions in a recoverable way (i.e. unwinding the stack and heap successfully). This will be very different from other versions of MMBasic and you will only be able to recover from errors with a reset I will, of course, attempt to handle as many error conditions as I can but it is completely certain that there will be many more that can't be handled |
||||
LucV Regular Member Joined: 19/02/2023 Location: NetherlandsPosts: 62 |
Thank you !!! Luc's tech Blog |
||||
LucV Regular Member Joined: 19/02/2023 Location: NetherlandsPosts: 62 |
I can't help it. I keep experimenting and keep running into problems. Here is an example of an api that works in the browser http://api.coindesk.com/v1/bpi/currentprice.json Tranlated: Dim buff%(512) WEB ntp Dim report$="/v1/bpi/currentprice.json" Dim b$= "GET "+report$+Chr$(10)+Chr$(13) WEB open tcp client "api.coindesk.com",80 WEB TCP CLIENT REQUEST b$,buff%(),10000 WEB close tcp client LongString print buff%() This gives a bunch of HTTP errors: > RUN Connected( <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.or> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859> <TITLE>ERROR: The request could not be satisfied</TITLE> </HEAD><BODY>c <H1>400 ERROR</H1>U <H2>The request could not be satisfied.</H2> <HR noshade size="1px"> Bad request.r Trying the HTTPS version gives no difference: Dim buff%(512) WEB ntp Dim b$= "GET /v1/bpi/currentprice.json" WEB open tls client "api.coindesk.com",443 WEB tls CLIENT REQUEST b$,buff%(),10000 WEB close tlS client LongString print buff%() My api for sending to Telegram gives also an error: error writing data, err=-6[9] WEB tls CLIENT REQUEST b$,buff%(),10000 Error : write failed -6 Sorry to be a nuisance. But progress is being made. Take your time. This is just for information. I presume there are not many users playing with this. So it does not have to get a big priority on your end. Luc Luc's tech Blog |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9144 |
I can't realistically diagnose these unless you can somehow get me a listing of what the browser is sending - wireshark might do it |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
I am surprised that you were able to implement TLS. It doesn't seem to have upset my server side testing and will come in handy for many users. Luc's site seems to use CloudFront and I often hear programmers complaining about issues with CloudFront Jim VK7JH MMedit MMBasic Help |
||||
atmega8 Guru Joined: 19/11/2013 Location: GermanyPosts: 722 |
Sorry for may be stupid Questions.. HTML / Json complete new World for me. Can someone please explain what this "Json$" is doing, where it comes from, where it is / Documenation/Manual? Something new inside mmbasic? Print Json$(buff%(),"setup") Print Json$(buff%(),"punchline") THX |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 9144 |
See the cmm2 manual for details |
||||
atmega8 Guru Joined: 19/11/2013 Location: GermanyPosts: 722 |
Peter, found it, understand it, Thank You. JSON$(array%(),string$) Returns a string representing a specific item out of the JSON input stored in the longstring array%() Examples taken from api.openweathermap.org JSON$(a%(), “name”) JSON$(a%(), “coord.lat”) JSON$(a%(), “weather[0].description”) JSON$(a%(),”list[4].weather[0].description |
||||
pwillard Senior Member Joined: 07/06/2022 Location: United StatesPosts: 292 |
Hmmm... I still can't escape the problem at boot time where I get: Assigned Address: 192.168.1.224 ntp address 198.137.202.32 NTP FAILURE Always with the NTP failure. |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
Perhaps your network is blocking requests to NTP port 123. It might be diverting to your ISP etc and the pico may not like that. Jim VK7JH MMedit MMBasic Help |
||||
pwillard Senior Member Joined: 07/06/2022 Location: United StatesPosts: 292 |
Yeah, it's weird the SECOND attempt always succeeds. I've also been trying to collect some notes to use as a reference to PicoMiteWeb so I can start to use this new stuff effectively. SmallBook |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
If the second attempt always works, forget my suggestion. Have you tried a few seconds delay before the NTP command? My router always needs two attempts to connect which is a pain but not difficult to allow for in the code. Jim VK7JH MMedit MMBasic Help |
||||
Hans Senior Member Joined: 18/10/2022 Location: CanadaPosts: 116 |
I had the exact same thing but then it just went away, don't know why. Also is there a way to know the requesting ip address of my web page? Hans ... Edited 2023-02-28 11:50 by Hans |
||||
Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 847 |
@pwillard, Your SmallBook is fantastic. I've scanned it briefly and have now started to read it more thoroughly. It is just what I was hoping 'someone' would do. May I suggest (unless others suggest otherwise) that you start a new thread because it might otherwise get lost in a sea of updates. Well done, Andrew |
||||
Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 847 |
Peter (or maybe someone else)?, "WEB NTP xx" is fantastic - it even sets DATE$, TIME$. Thanks. What does it do with daylight saving time (DST)? I assume that we adjust xx accordingly - is that so? Cheers, Andrew Edited 2023-03-03 10:22 by Andrew_G |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
Yes, DST is too political to be easy. The date formulae is subject to the whim of our political masters (a frightening thought). The quandary we have is, you can't calculate DST until you know the date. This prevents you changing the UTC offset before calling WEB NTP. I am considering, getting the date assuming no DST then check the date to see if it needs adjusting. If so get WEB NTP again with the adjusted offset so, from then on NTP keeps the time until the next change in time zone. If your system is running 335 days a year, you will need a daily(?) check to see if the UTC offset needs adjusting. We have few weeks to get the code sorted out. Might be easier to move to Queensland... Edit ' DIM dst DIM Tzone = 10 dst = 1 WEB ntp Tzone+dst PRINT time$ dst = 0 WEB ntp Tzone+dst PRINT ti9me$ RUN ntp address 162.159.200.123 got ntp response: 03/03/2023 12:04:39 12:04:39 ntp address 162.159.200.123 got ntp response: 03/03/2023 11:04:39 11:04:39 > Variables are OK so you just need to calculate DST or not. Jim Edited 2023-03-03 11:09 by TassyJim VK7JH MMedit MMBasic Help |
||||
Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 847 |
Thanks Jim, That makes sense. I've got some code (somewhere) that checks the date and time and gives DST = 0 or 1. There is an hour each year where it and I get confused. Found it here . It triggered the discussion about how best to exit nested Do/Loops. (I'm playing with two Picos (one normal, one W; for Mick and myself. It gets the OpenWeather data on one and sends it by serial to the other for display with GUI on an LCD. So far so good.) Cheers, Andrew (Queensland is OK for a few months and Tassie is not bad either . . .) Edited 2023-03-03 11:29 by Andrew_G |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6103 |
' Tassyjim - March 2023 DIM Tzone = 10 WEB ntp Tzone PRINT TIME$ WEB ntp Tzone+dst() PRINT TIME$ FUNCTION dst() LOCAL aprstart, octstart, dst1, dst2, dateNow$ dateNow$ = DATE$ daynumnow = EPOCH(datenow$+" 00:00:00")/86400 aprstart = EPOCH("01-04-"+MID$(dateNow$,7,4)+" 00:00:00")/86400 dst1 = 3-(aprstart MOD 7) dst1 = aprstart+dst1 ' first sunday in april in current year octstart = EPOCH("01-10-"+MID$(dateNow$,7,4)+" 00:00:00")/86400 dst2 = 3-(octstart MOD 7) dst2 = octstart+ dst2 ' first sunday in october in current year PRINT DATETIME$(dst1*86400) ' for debug PRINT DATETIME$(dst2*86400) IF daynumnow < dst1 OR daynumnow >= dst2 THEN ' swap for northern hemisphere dst = 1 ELSE dst = 0 ENDIF END FUNCTION hard coded for Australia VK7JH MMedit MMBasic Help |
||||
Andrew_G Guru Joined: 18/10/2016 Location: AustraliaPosts: 847 |
Hi Jim, I guess I can stop packing my bags for Queensland then. Thanks, Andrew |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 359 |
Thanks TassyJim. It will become a popular piece of code for many Pico W programs. For the nothern hemisphere I just swapped these ...... dst = 0 'south=1, north=0 ELSE dst = 1 'south=0, north=1 ..... /Pluto |
||||
Page 1 of 2 |
Print this page |