Changes for page 05 Lua Script

Last modified by Devin Chen on 2025/03/04 14:07

From version 38.1
edited by Hunter
on 2023/07/07 18:14
Change comment: There is no comment for this version
To version 38.2
edited by Hunter
on 2023/07/10 12:01
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -296,3 +296,219 @@
296 296  
297 297  (% style="text-align:center" %)
298 298  [[image:WordWrapDisplayResult.png]]
299 +
300 += 16 Weather forecast HTTP API request =
301 +
302 +The example shows how to parse value from HTTP response body, and display into HMI internal address. The test forecast official website is [[https:~~/~~/www.weatherapi.com/>>url:https://www.weatherapi.com/]]
303 +
304 +From the API document, the one day forecast response would be like the follows:
305 +
306 +{{code language="JSON"}}
307 +{
308 + "location": {
309 + "name": "London",
310 + "region": "City of London, Greater London",
311 + "country": "United Kingdom",
312 + "lat": 51.52,
313 + "lon": -0.11,
314 + "tz_id": "Europe/London",
315 + "localtime_epoch": 1688961236,
316 + "localtime": "2023-07-10 4:53"
317 + },
318 + "current": {
319 + "last_updated_epoch": 1688960700,
320 + "last_updated": "2023-07-10 04:45",
321 + "temp_c": 14.0,
322 + "temp_f": 57.2,
323 + "is_day": 0,
324 + "condition": {
325 + "text": "Partly cloudy",
326 + "icon": "//cdn.weatherapi.com/weather/64x64/night/116.png",
327 + "code": 1003
328 + },
329 + "wind_mph": 4.3,
330 + "wind_kph": 6.8,
331 + "wind_degree": 220,
332 + "wind_dir": "SW",
333 + "pressure_mb": 1020.0,
334 + "pressure_in": 30.12,
335 + "precip_mm": 0.0,
336 + "precip_in": 0.0,
337 + "humidity": 88,
338 + "cloud": 50,
339 + "feelslike_c": 13.3,
340 + "feelslike_f": 56.0,
341 + "vis_km": 10.0,
342 + "vis_miles": 6.0,
343 + "uv": 1.0,
344 + "gust_mph": 10.5,
345 + "gust_kph": 16.9
346 + },
347 + "forecast": {
348 + "forecastday": [
349 + {
350 + "date": "2023-07-10",
351 + "date_epoch": 1688947200,
352 + "day": {
353 + "maxtemp_c": 24.4,
354 + "maxtemp_f": 75.9,
355 + "mintemp_c": 14.1,
356 + "mintemp_f": 57.4,
357 + "avgtemp_c": 19.6,
358 + "avgtemp_f": 67.2,
359 + "maxwind_mph": 15.4,
360 + "maxwind_kph": 24.8,
361 + "totalprecip_mm": 0.0,
362 + "totalprecip_in": 0.0,
363 + "totalsnow_cm": 0.0,
364 + "avgvis_km": 10.0,
365 + "avgvis_miles": 6.0,
366 + "avghumidity": 60.0,
367 + "daily_will_it_rain": 0,
368 + "daily_chance_of_rain": 0,
369 + "daily_will_it_snow": 0,
370 + "daily_chance_of_snow": 0,
371 + "condition": {
372 + "text": "Partly cloudy",
373 + "icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
374 + "code": 1003
375 + },
376 + "uv": 5.0
377 + },
378 + "astro": {
379 + "sunrise": "04:55 AM",
380 + "sunset": "09:16 PM",
381 + "moonrise": "12:26 AM",
382 + "moonset": "02:01 PM",
383 + "moon_phase": "Last Quarter",
384 + "moon_illumination": "51",
385 + "is_moon_up": 1,
386 + "is_sun_up": 0
387 + },
388 + "hour": [
389 + {
390 + "time_epoch": 1688943600,
391 + "time": "2023-07-10 00:00",
392 + "temp_c": 16.2,
393 + "temp_f": 61.2,
394 + "is_day": 0,
395 + "condition": {
396 + "text": "Clear",
397 + "icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
398 + "code": 1000
399 + },
400 + "wind_mph": 7.2,
401 + "wind_kph": 11.5,
402 + "wind_degree": 223,
403 + "wind_dir": "SW",
404 + "pressure_mb": 1021.0,
405 + "pressure_in": 30.14,
406 + "precip_mm": 0.0,
407 + "precip_in": 0.0,
408 + "humidity": 74,
409 + "cloud": 6,
410 + "feelslike_c": 16.2,
411 + "feelslike_f": 61.2,
412 + "windchill_c": 16.2,
413 + "windchill_f": 61.2,
414 + "heatindex_c": 16.2,
415 + "heatindex_f": 61.2,
416 + "dewpoint_c": 11.6,
417 + "dewpoint_f": 52.9,
418 + "will_it_rain": 0,
419 + "chance_of_rain": 0,
420 + "will_it_snow": 0,
421 + "chance_of_snow": 0,
422 + "vis_km": 10.0,
423 + "vis_miles": 6.0,
424 + "gust_mph": 10.7,
425 + "gust_kph": 17.3,
426 + "uv": 1.0
427 + },
428 + {
429 + "time_epoch": 1688947200,
430 + "time": "2023-07-10 01:00",
431 + "temp_c": 15.7,
432 + "temp_f": 60.3,
433 + "is_day": 0,
434 + "condition": {
435 + "text": "Overcast",
436 + "icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
437 + "code": 1009
438 + },
439 + "wind_mph": 7.2,
440 + "wind_kph": 11.5,
441 + "wind_degree": 232,
442 + "wind_dir": "SW",
443 + "pressure_mb": 1021.0,
444 + "pressure_in": 30.14,
445 + "precip_mm": 0.0,
446 + "precip_in": 0.0,
447 + "humidity": 75,
448 + "cloud": 100,
449 + "feelslike_c": 15.7,
450 + "feelslike_f": 60.3,
451 + "windchill_c": 15.7,
452 + "windchill_f": 60.3,
453 + "heatindex_c": 15.7,
454 + "heatindex_f": 60.3,
455 + "dewpoint_c": 11.3,
456 + "dewpoint_f": 52.3,
457 + "will_it_rain": 0,
458 + "chance_of_rain": 0,
459 + "will_it_snow": 0,
460 + "chance_of_snow": 0,
461 + "vis_km": 10.0,
462 + "vis_miles": 6.0,
463 + "gust_mph": 10.5,
464 + "gust_kph": 16.9,
465 + "uv": 1.0
466 + },
467 + ...
468 + {
469 + "time_epoch": 1689026400,
470 + "time": "2023-07-10 23:00",
471 + "temp_c": 19.0,
472 + "temp_f": 66.2,
473 + "is_day": 0,
474 + "condition": {
475 + "text": "Overcast",
476 + "icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
477 + "code": 1009
478 + },
479 + "wind_mph": 9.4,
480 + "wind_kph": 15.1,
481 + "wind_degree": 192,
482 + "wind_dir": "SSW",
483 + "pressure_mb": 1015.0,
484 + "pressure_in": 29.96,
485 + "precip_mm": 0.0,
486 + "precip_in": 0.0,
487 + "humidity": 66,
488 + "cloud": 100,
489 + "feelslike_c": 19.0,
490 + "feelslike_f": 66.2,
491 + "windchill_c": 19.0,
492 + "windchill_f": 66.2,
493 + "heatindex_c": 19.0,
494 + "heatindex_f": 66.2,
495 + "dewpoint_c": 12.4,
496 + "dewpoint_f": 54.3,
497 + "will_it_rain": 0,
498 + "chance_of_rain": 0,
499 + "will_it_snow": 0,
500 + "chance_of_snow": 0,
501 + "vis_km": 10.0,
502 + "vis_miles": 6.0,
503 + "gust_mph": 13.0,
504 + "gust_kph": 20.9,
505 + "uv": 1.0
506 + }
507 + ]
508 + }
509 + ]
510 + }
511 +}
512 +{{/code}}
513 +
514 +[[Download link>>https://ftp.we-con.com.cn/Download/WIKI/PI%20HMI/Demo/Lua%20Script/luahttp.zip]]