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: How to read enegyprice from a website
Page 2 of 2 | |||||
Author | Message | ||||
lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3150 |
Terrific insight and clue. With an ESP32-C3Supermini running Annex, in the "immediate" window, I did r$="http://www.sahkohinta-api.fi/api/v1/halpa?tunnit=1&tulos=haja&aikaraja=2024-11-15" a$=wget$(r$,80) wlog a$ wlog json$(a$,"hinta") And got back: HTTP/1.1 200 OK Date: Sat, 16 Nov 2024 14:17:51 GMT Server: Apache/2.4.57 (Unix) OpenSSL/3.0.2 X-Powered-By: PHP/7.4.33 Upgrade: h2 Connection: Upgrade, Keep-Alive Keep-Alive: timeout=5, max=100 Transfer-Encoding: chunked Content-Type: application/json [{"aikaleima_suomi":"2024-11-15T23:00","aikaleima_utc":"2024-11-15T21:00","hinta":"-0.08700"}] -0.08700 Does "hinta":"-0.08700" provide the information desired? (After googling, I see that "hinta" translates as "price". Is the price in Euros?) ~ Edited 2024-11-17 00:39 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3797 |
Similarly, this: telnet sahkohinta-api.fi 80 GET /api/v1/halpa?tunnit=2&tulos=haja&aikaraja=2024-11-15 HTTP/1.1 Host: www.sahkohinta-api.fi Accept: */* (and an empty line) got me: bb [{"aikaleima_suomi":"2024-11-15T23:00","aikaleima_utc":"2024-11-15T21:00","hinta":"-0.08700"},{"aikaleima_suomi":"2024-11-15T22:00","aikaleima_utc":"2024-11-15T20:00","hinta":"-0.02500"}] 0 The bb is probably a hex char count John |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 357 |
@Iizby, The price is in eurocents/kWh. The result for that point in time is correct. The request you made actually looks up the cheapest hour on that date. r$="http://www.sahkohinta-api.fi/api/v1/halpa?tunnit=1&tulos=haja&aikaraja=2024-11-15" hints: halpa?: cheapest, tunnit=1: return 1 answer, tulos=haja: results in price order not timeorder So ESP32 with Annex would be one possible solution, if WebMite can't make it. Thanks a lot! |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 357 |
@John, your request asked for the two cheapest hours on 2024-11-15. See my revious post for explanation/translation of the request. Do you think that it is somehow possible to transform your telnet testing into WebMite or will the HTTPS/HTTP issue be a definite stop? Thank you so much! Fred |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3797 |
All I did is http so will work on webmite. Just be sure to use both CR and LF at the end of each line and you need an extra blank line to finish the query. The site doesn't seem to like square brackets so either the API doesn't want them or something else. John |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 357 |
John, I have never used TELNET on WebMite. Have tried to search in the documentation, but unfortunately I did not find anything that could help me forward. I have set WebMite MMBasic Version 6.00.00RC15 OPTION WIFI HuaHuaNisse, ***********, PICOE6616408435 OPTION TCP SERVER PORT 80 OPTION TELNET CONSOLE ON but how to proceed? Fred |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3797 |
No need. Just do the kind of thing you started out doing with that TCP stuff. All you need is to change what you send to be like the strings I sent on the lines following the telnet command. Your b$ needs changing a bit. Start by taking out the square brackets and add the extra lines (with CR LF between them) ( the lines being the Host and Accept). John Edited 2024-11-17 04:18 by JohnS |
||||
Pluto Guru Joined: 09/06/2017 Location: FinlandPosts: 357 |
'Find cheapest electricity hour 'https://www.sahkohinta-api.fi/api/v1/halpa?tunnit=2&tulos=haja&aikaraja=2022-11-20 ' 'Warm Thanks to JohnS and Iizby for absolutely essential support. ' OPTION EXPLICIT OPTION DEFAULT NONE Dim buff%(4096/8) DIM a% = 1000 DIM url$="sahkohinta-api.fi" Dim s1$,s2$,s3$,s4$ 'parts of the request string s1$="GET /api/v1/halpa?tunnit=1&tulos=haja&aikaraja=2024-11-17 HTTP/1.1"+Chr$(13)+Chr$(10) s2$="Host: www.sahkohinta-api.fi"+Chr$(13)+Chr$(10) s3$="Accept: */*"+Chr$(13)+Chr$(10) s4$=""+Chr$(13)+Chr$(10) WEB open TCP CLIENT "www.sahkohinta-api.fi",80 WEB TCP CLIENT REQUEST s1$+s2$+s3$+s4$+s4$,buff%(),10000 WEB close TCP CLIENT a%=LinStr(buff%(),"{")-1: print "a%=";a% If a% <> -1 Then LongString trim buff%(),a% LongString print buff%() Print Json$(buff%(),"hinta");" cent/kWh at ";Json$(buff%(),"aikaleima_suomi") endif end RUN Connected a%= 225 {"aikaleima_suomi":"2024-11-17T02:00","aikaleima_utc":"2024-11-17T00:00","hinta":"-0.00100"}] 0 -0.00100 cent/kWh at 2024-11-17T02:00 > After some trials it works. I am so glad that it could be done with WebMite and that I can avoid the ESPs. Thanks again for your unlimited support. No way I could have solved it myself! I have learned a few new things; Now it just remains to remember. Fred |
||||
JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 3797 |
Excellent - I'm so glad you got it working! John |
||||
Page 2 of 2 |
Print this page |