Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:30 26 Oct 2025 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: How to read enegyprice from a website

     Page 2 of 2    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3437
Posted: 02:22pm 16 Nov 2024
Copy link to clipboard 
Print this post

  JohnS said  I turned on some debugging:

wget -d -v -S 'http://www.sahkohinta-api.fi/api/v1/halpa?tunnit=1&tulos=haja&aikaraja=2024-11-15'


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 Kingdom
Posts: 4098
Posted: 04:15pm 16 Nov 2024
Copy link to clipboard 
Print this post

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: Finland
Posts: 380
Posted: 04:54pm 16 Nov 2024
Copy link to clipboard 
Print this post

@Iizby,
  Quote  Does "hinta":"-0.08700" provide the information desired?

(After googling, I see that "hinta" translates as "price". Is the price in Euros?)

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: Finland
Posts: 380
Posted: 05:02pm 16 Nov 2024
Copy link to clipboard 
Print this post

@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 Kingdom
Posts: 4098
Posted: 05:08pm 16 Nov 2024
Copy link to clipboard 
Print this post

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: Finland
Posts: 380
Posted: 05:31pm 16 Nov 2024
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 4098
Posted: 06:15pm 16 Nov 2024
Copy link to clipboard 
Print this post

  Pluto said  John,
I have never used TELNET on WebMite.

Fred

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: Finland
Posts: 380
Posted: 07:54pm 16 Nov 2024
Copy link to clipboard 
Print this post

   
'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 Kingdom
Posts: 4098
Posted: 02:09pm 17 Nov 2024
Copy link to clipboard 
Print this post

Excellent - I'm so glad you got it working!

John
 
Pluto
Guru

Joined: 09/06/2017
Location: Finland
Posts: 380
Posted: 06:31pm 13 Oct 2025
Copy link to clipboard 
Print this post

The electricityprice-meter from last year has been in constant operation since Jan 2025. Placed in the kitchen it gives a good and easy overwiew of cheap and expensive hours. Better to heat the sauna when close to 0 c/kWh than at 60 c/kWh.



(Don't understand why is it upside down. Tried to turn it and still...




To make it a bit more complicated the tariffs are now changing each 15 minute.
Got some new Pico 2W and started to work on a new meter.

The problem today is that I am not able to receive the full datastring for all of the 96 15minutes data without errors. I had to divide the data into 2 12hour parts, which are received by 2 separate WEB TCP CLIENT REQUEST (which is not a problem).
The stringlenght for 12h is LLEN(buff%())=4493 and 4470.
I have now set the buffer to Dim buff%(4096*4/8), which should be enough.

My question is: What is the max lenght of data that WEBmite's buffer can handle?
At best I got about 90 of the 96 datapoints in one shot. The error when trying to get all points was some extra nonsence "eg. 1 10c" in the received textstring. That ruined the Json$ parsing of the data.


option list
WebMite MMBasic RP2350A Edition V6.01.00RC0
OPTION AUTORUN  ON
OPTION FLASH SIZE 4194304
OPTION COLOURCODE ON
OPTION CPUSPEED (KHz) 150000
OPTION WIFI HuaHuaNisse, ***********, PICO8F2205DCB04

The received data looks like this:
Connected
LLEN(buff%(): 4493
a%= 227
buff%()=       HTTP/1.1 200 OK
Date: Mon, 13 Oct 2025 14:22:01 GMT
Server: Apache/2.4.57 (Unix) OpenSSL/3.0.2
X-Powered-By: PHP/8.1.18
Upgrade: h2
Connection: Upgrade
Transfer-Encoding: chunked
Content-Type: application/json

10a4 (this is also something not belonging to the data, but it does not disturb)
[{"aikaleima_suomi":"2025-10-14T12:00","aikaleima_utc":"2025-10-14T09:00","hinta":20.49},{"aikaleima_suomi":"2025-10-14T12:15","aikaleima_utc":"2025-10-14T09:15","hinta":19.709},.......etc, etc....


Pluto
 
     Page 2 of 2    
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025