If we want to use the information such as sunrise and sunset in the system, we can use an external service for this purpose, e.g.: https://sunrise-sunset.org/.

 

According to the example on  https://sunrise-sunset.org

the API query looks as following:

API call: https://api.sunrise-sunset.org/json?lat=36.7201600&lng=-4.4203400.


Below is presented how you can easily obtain this information:

  • Create the HttpRequest periphery object:

    HttpRequest - used to send HTTP requests (GET, POST type) to the specified host. Standard content-types are supported, including JSON, XML


  • The following parameters should be set in the HttpRequest object:

    Where:

            Host: https://api.sunrise-sunset.org
            Path: /json
            QueryStringParams: lat=36.7201600&lng=-4.4203400


  • The next step is to create user features of the string type:


  • Then prepare the script:
    local resp=GateHttp->HttpRequest->ResponseBody
    GateHttp->sunrise=resp.results.sunrise
    GateHttp->sunset=resp.results.sunset
    GateHttp->solar_noon=resp.results.solar_noon
    GateHttp->day_length=resp.results.day_length
    GateHttp->civil_twilight_begin=resp.results.civil_twilight_begin
    GateHttp->civil_twilight_end=resp.results.civil_twilight_end
    GateHttp->nautical_twilight_begin=resp.results.nautical_twilight_begin
    GateHttp->nautical_twilight_end=resp.results.nautical_twilight_end
    GateHttp->astronomical_twilight_begin=resp.results.astronomical_twilight_begin
    GateHttp->astronomical_twilight_end=resp.results.astronomical_twilight_endlocal resp=GateHttp->Http_Request->ResponseBody
    GateHttp->sunrise=resp.results.sunrise
    GateHttp->sunset=resp.results.sunset
    GateHttp->solar_noon=resp.results.solar_noon
    GateHttp->day_length=resp.results.day_length
    GateHttp->civil_twilight_begin=resp.results.civil_twilight_begin
    GateHttp->civil_twilight_end=resp.results.civil_twilight_end
    GateHttp->nautical_twilight_begin=resp.results.nautical_twilight_begin
    GateHttp->nautical_twilight_end=resp.results.nautical_twilight_end
    GateHttp->astronomical_twilight_begin=resp.results.astronomical_twilight_begin
    GateHttp->astronomical_twilight_end=resp.results.astronomical_twilight_end
    HTML


  • Assign the script to the OnResponse event in the Http_Request periphery object:


  • Then, the configuration should be sent to the CLU.

    After the configuration has been successfully sent, the SendRequest method should be called in the Control tab of the Http_Request periphery object.


  • After calling the method, the StatusCode feature should receive the value 200.
    User features values should receive appropriate values:The obtained data can be displayed in the mobile application and Smart Panel or use to create logic in the system.