Unexpected behaviour on REQUESTHTTPX chain?

Hello, I’ve tried to develop a sensor solution, and somehow I can’t get to properly handle events.

FUNCTION query_sensors
    ONSTATUS "@on_query_sensor1"
    $url$ = "http://" + iolink_address$ + ":" + iolink_port$ + "/iolinkmaster/port[1]/iolinkdevice/pdin/getdata"
    REQUESTHTTPX $url$, "GET"
    PRINT "qs> Querying sensor 1 " + $url$
    
    ONSTATUS "@on_query_sensor2"
    $url$ = "http://" + iolink_address$ + ":" + iolink_port$ + "/iolinkmaster/port[2]/iolinkdevice/pdin/getdata"
    REQUESTHTTPX $url$, "GET"
    PRINT "qs> Querying sensor 2 " + $url$
    
    ONSTATUS "@on_query_sensor3"
    $url$ = "http://" + iolink_address$ + ":" + iolink_port$ + "/iolinkmaster/port[3]/iolinkdevice/pdin/getdata"
    REQUESTHTTPX $url$, "GET"
    PRINT "qs> Querying sensor 3 " + $url$
ENDFN

FUNCTION on_query_sensor1
  $oqs_sensor_id% = 1
  $oqs_read_temperature% = 1
  $oqs_read_humidity% = 1
  $oqs_action_id% = GETSYS PRG, "EVTINFO"
  SETSYS PRG, "ACTIONID", $oqs_action_id%
  $oqs_action_status% = GETSYS PRG, "ACTIONSTAT"
  PRINT "oqs1> Event ActionID: " + STR$($oqs_action_id%) + " Event ActionStatus: " + STR$($oqs_action_status%)
  IF ($oqs_action_status% = -2) THEN
    //PRINT "oqs1> ID NOT FOUND, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = -1) THEN
    //PRINT "oqs1> IN PROGRESS, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = 0) THEN
    //PRINT "oqs1> SUCCESS, ActionID: " + STR$($oqs_action_id%)
    $oqs_response_status_code$ = RESPONSEHTTPX "STATUSCODE"
    $oqs_response_body$ = RESPONSEHTTPX "RESPONSE-BODY"
    PRINT "oqs1> Response Status Code: " + $oqs_response_status_code$ + " Response Body: " + $oqs_response_body$
    $oqs_string_position% = INSTR 1, $oqs_response_body$, "value"
    IF ($oqs_string_position% > 0) THEN
      IF ($oqs_read_temperature% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 8)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 9)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 10)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 11)
        //PRINT $oqs_value_hex$
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = -30.0+((80.0-(-30.0))*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "temperatura" + STR$($oqs_sensor_id%)
        PRINT "oqs1> tem " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF  
      IF ($oqs_read_humidity% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 16)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 17)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 18)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 19)
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = 0.0+((100.0-0.0)*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "humedad" + STR$($oqs_sensor_id%)
        PRINT "oqs1> hum " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF
    ENDIF
  ELSE IF ($oqs_action_status% > 0) THEN
    //PRINT "oqs1> ERROR, ActionID: " + STR$($oqs_action_id%) + " (ERROR = " + STR$($oqs_action_status%) + ")" 
  ENDIF ENDIF ENDIF ENDIF
ENDFN

FUNCTION on_query_sensor2
  $oqs_sensor_id% = 2
  $oqs_read_temperature% = 1
  $oqs_read_humidity% = 1
  $oqs_action_id% = GETSYS PRG, "EVTINFO"
  SETSYS PRG, "ACTIONID", $oqs_action_id%
  $oqs_action_status% = GETSYS PRG, "ACTIONSTAT"
  PRINT "oqs2> Event ActionID: " + STR$($oqs_action_id%) + " Event ActionStatus: " + STR$($oqs_action_status%)
  IF ($oqs_action_status% = -2) THEN
    //PRINT "oqs2> ID NOT FOUND, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = -1) THEN
    //PRINT "oqs2> IN PROGRESS, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = 0) THEN
    //PRINT "oqs2> SUCCESS, ActionID: " + STR$($oqs_action_id%)
    $oqs_response_status_code$ = RESPONSEHTTPX "STATUSCODE"
    $oqs_response_body$ = RESPONSEHTTPX "RESPONSE-BODY"
    PRINT "oqs2> Response Status Code: " + $oqs_response_status_code$ + " Response Body: " + $oqs_response_body$
    $oqs_string_position% = INSTR 1, $oqs_response_body$, "value"
    IF ($oqs_string_position% > 0) THEN
      IF ($oqs_read_temperature% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 8)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 9)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 10)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 11)
        //PRINT $oqs_value_hex$
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = -30.0+((80.0-(-30.0))*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "temperatura" + STR$($oqs_sensor_id%)
        PRINT "oqs2> tem " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF  
      IF ($oqs_read_humidity% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 16)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 17)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 18)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 19)
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = 0.0+((100.0-0.0)*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "humedad" + STR$($oqs_sensor_id%)
        PRINT "oqs2> hum " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF
    ENDIF
  ELSE IF ($oqs_action_status% > 0) THEN
    //PRINT "oqs2> ERROR, ActionID: " + STR$($oqs_action_id%) + " (ERROR = " + STR$($oqs_action_status%) + ")" 
  ENDIF ENDIF ENDIF ENDIF
ENDFN

FUNCTION on_query_sensor3
  $oqs_sensor_id% = 3
  $oqs_read_temperature% = 1
  $oqs_read_humidity% = 0
  $oqs_action_id% = GETSYS PRG, "EVTINFO"
  SETSYS PRG, "ACTIONID", $oqs_action_id%
  $oqs_action_status% = GETSYS PRG, "ACTIONSTAT"
  PRINT "oqs3> Event ActionID: " + STR$($oqs_action_id%) + " Event ActionStatus: " + STR$($oqs_action_status%)
  IF ($oqs_action_status% = -2) THEN
   // PRINT "oqs3> ID NOT FOUND, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = -1) THEN
    //PRINT "oqs3> IN PROGRESS, ActionID: " + STR$($oqs_action_id%)
  ELSE IF ($oqs_action_status% = 0) THEN
    //PRINT "oqs3> SUCCESS, ActionID: " + STR$($oqs_action_id%)
    $oqs_response_status_code$ = RESPONSEHTTPX "STATUSCODE"
    $oqs_response_body$ = RESPONSEHTTPX "RESPONSE-BODY"
    PRINT "oqs3> Response Status Code: " + $oqs_response_status_code$ + " Response Body: " + $oqs_response_body$
    $oqs_string_position% = INSTR 1, $oqs_response_body$, "value"
    IF ($oqs_string_position% > 0) THEN
      IF ($oqs_read_temperature% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 8)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 9)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 10)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 11)
        //PRINT $oqs_value_hex$
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = -30.0+((80.0-(-30.0))*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "temperatura" + STR$($oqs_sensor_id%)
        PRINT "oqs3> tem " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF  
      IF ($oqs_read_humidity% = 1) THEN
        $oqs_value_hex$ =                   $oqs_response_body$($oqs_string_position% + 16)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 17)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 18)
        $oqs_value_hex$ = $oqs_value_hex$ + $oqs_response_body$($oqs_string_position% + 19)
        $oqs_value_dec = DEC($oqs_value_hex$) * 0.001
        $oqs_value_dec = 0.0+((100.0-0.0)*($oqs_value_dec-0.0)/(10.0-0.0))
        $oqs_value_str$ = SFMT $oqs_value_dec, 20, 0, "%.2f"
        $oqs_tag_var$ = "humedad" + STR$($oqs_sensor_id%)
        PRINT "oqs3> hum " + $oqs_tag_var$ + " = " + $oqs_value_str$
        SETIO $oqs_tag_var$, $oqs_value_str$
      ENDIF
    ENDIF
  ELSE IF ($oqs_action_status% > 0) THEN
    //PRINT "oqs3> ERROR, ActionID: " + STR$($oqs_action_id%) + " (ERROR = " + STR$($oqs_action_status%) + ")" 
  ENDIF ENDIF ENDIF ENDIF
ENDFN

Somehow, I always get the event being handled by the on_query_sensor3 “event handler”

Is there anything I can do to fix this? I can’t rely on Timers as I got 2 already assigned (and one extra for query_sensors)

I’ve just created a ONCREATE call ontop to a “@master_event_handler” and I’ll switch for each possible request, storing the value at the tag zone.

That kind of did the trick.

STILL I’d like some insight on the issue.

The overview of the problem is, I call few REQUESTHTTPX in series, having different ONSTATUS instructions.

This makes sense as I declare one “ONSTATUS” handler for each request.

On the developers manual it says that once I declare a ONSTATUS, it will be held on the BASIC queue.

There’s not much details on the limitations (if any) on the request count, event policy or even the expected behaviour.

I’d like to know if this is intended, and-or how I’m expected to throw multiple requests on the same “BASIC cycle”.

It looks like it will just hold the last ONSTATUS declaration. Is this a global variable or will it get stored on the BASIC queue?

I’d expect that if you create 3 requests in series, the ONSTATUS declaration will be stored on the queue, one ONSTATUS per request.

I’d like to have some feedback on this matter, and probably analyse the problem.

Thank you.

This has something to do with the issue here:
https://techforum.ewon.biz/thread-2375.html

Hi @pvalades,

Sorry for the delay. We are migrating to a new platform. Please go to support.hms-networks.com and either create a support case or a forum topic there for help with this issue.

You can also visit the Ewon developer forum that you linked above.

Thank you!