LogoLogo
HomeSign UpGithub
  • Home
  • Release Notes
  • Getting Started
    • Create your first Test
    • Create Run Settings
    • Analyze the results
      • Job Summary
      • Logs
      • State
      • Payload
    • Look deeper with Metrics
  • Concepts
    • Workspaces
      • Role Based Access Control (RBAC)
      • Invitation Management
      • GitHub Integration
      • Deletion of Workspaces
      • System Status
    • Understanding Tests
      • Stages Management
        • Init Stage
        • Running Stage(s)
        • Finished State
      • Generating Messages
        • Scripting Environment
        • State Object
      • Response Handler
      • Preview Tests
      • Exporting/Importing Tests
        • Import OpenAPI JSON/YAML
      • Locking/Unlocking a test
    • Stateful Simulation
      • Mapping the IoT device lifecycle
    • Protocol Settings
      • MQTT
      • HTTP
      • Using other protocols
    • Run Settings
      • Network Simulation
      • Execution Strategies
      • Client Distribution
    • Scenarios
    • Glob Storage
    • Metrics
    • Mailbox
    • Licensing and Limits
    • Deployment Models
  • Additional Helpers
    • External Libraries
    • Inbuilt Libraries
    • IoTIFY Helper Functions
      • Job Functions
      • Messaging Functions
      • Glob Functions
      • Metrics Functions
      • Mailbox Functions
      • Data Generation Functions
  • platform integrations
    • AWS IoT Connector
  • Guides
    • Smart City
    • Smart Home
    • Load Testing Kafka
  • IoT Testing
    • Overview
      • Feed offline sensor data from Google Sheets to your IoT platform
    • Functional Testing
      • Basic functional test
      • Geofencing Validation
    • Performance Testing
      • MQTT end to end latency Measurement
    • Security Testing
    • Load Testing
    • Test Automation & CI/CD integration
  • API
    • Simulation API
    • Glob APIs
    • Metrics API
  • Glossary
  • Create Account
  • TEMP
    • Getting Started
      • Beginner
      • Developer
      • Tester
    • Walkthrough
    • Protocol Settings
      • CoAP
      • Raw (TCP/UDP/TLS/DTLS)
      • LWM2M
      • NONE
    • Under the hood
    • Google Sheets API
    • Azure IoT
    • Losant IoT
      • Losant Connector
      • Parking Space Management
      • Waste Management
      • Connected Truck
      • Delivery Van
    • Google Cloud IoT Core
    • IBM Cloud
      • Simple Messaging
      • IBM Bluemix: Monitoring Energy Consumption
    • Dweet.io
    • JMeter and why it fails at IoT
Powered by GitBook
On this page

Was this helpful?

  1. Concepts
  2. Understanding Tests

Response Handler

IoT communication is bidirectional in nature, it includes both device-to-cloud and cloud-to-device communication. So far we have seen how to generate messages and send them to your IoT platform. Let's discuss how to handle the messages or commands coming from the server side.

The responses are handled by the receiver function in the device model. To handle such responses, go to the stage you want the logic to be in and then switch to the Receiver tab.

The handling of these messages are specific to the protocol in use, however, the common functions remain the same.

function receiver(response)
{ 
    console.log("Received a message on the subscribed topic ", response)
    state.received++;                
    state.recv_queue.push(response);            
}

It is important to understand that while a simulation is running, the handler may be invoked asynchronously. This is because the command from the server side could be initiated at any time. To be on the safer side and avoid any race condition, the subscription handler should be small and defer all actions to be executed in the next iteration call. In the above example, we have simply produced a log and pushed the received message to the receive queue.

Note that the subscription handler does not need to return any value.

The subscription handler could be invoked multiple times asynchronously while your simulation is running. That's why the results of the subscription should be stored in a queue rather than being processed, as a second run could overwrite the previous run's results.

While the basic function of the response handler is the same, the data that it contains varies with the protocol. To understand how to handle the data that is received for each protocol, follow the examples given below.

Response Handler for MQTT

In MQTT, a client could subscribe to any particular topic. The subscription topic can be specified in the template by enabling the subscription button in the protocol tab. When a publication is received on the chosen topic, the subscription handler is invoked with

function(response)
{
   //response.topic   - The MQTT topic on which subscription has been received
   //response.message - A buffer object which is sent for the subscription 
}

Response Handler for HTTP

In HTTP, the custom handler is invoked with the result of the operation performed. For example, if you did a POST operation, you could handle the response sent by the server.

function(response)
{
   //response.header - The header info for the operation that was performed
   //response.status- The status for the operation that was performed
   //response.body   - A buffer object which is sent by the server
}

Response Handler for NONE

In NONE, if loopback is set to on. The payload that was supposed to be sent is received back.

function(response)
{
   //response - The payload that was sent by the sender function
}
PreviousState ObjectNextPreview Tests

Last updated 2 years ago

Was this helpful?