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
  • HTTP REST APIs
  • MQTT APIs

Was this helpful?

  1. Additional Helpers
  2. IoTIFY Helper Functions

Messaging Functions

HTTP REST APIs

Within your device template, you could call a REST API and get data from an external source, or push data to an external service.

GET Requests

//requires the resource URL as the argument
rest.get({url: ''})  

rest.get({url:'https://httpbin.org/get'})

//you can also create a separate object for the argument and pass it to the API 
//headers are also supported
let options = {
	url: "https:https://httpbin.org/get",
	headers: {
		'content-type': 'application/json'
	}
}

rest.get(options)  

POST Requests

//requires the resource URL and a message object as the arguments
rest.post({url: '', json: {}})

rest.post({url:'https://httpbin.org/post', json: { hello: 'world'}})

//you can also create a separate object for the arguments and pass it to the API  
let obj = {
	username: "test_user",
	password: "dontusethis"
}

//headers are also supported
let options = {
	url: "https://httpbin.org/post",
	json: obj,
	headers: {
		'content-type': 'application/json'
	}
}

rest.post(options);

PUT Requests

//requires the resource URL and a message object as the arguments
rest.put({url: '', json: {}})

rest.put({url:'https://httpbin.org/put', json: { hello: 'world'}})

//you can also create a separate object for the arguments and pass it to the API  
let options = {
	url: "https://httpbin.org/put",
	json: { hello: 'world'},
	headers: {
		'content-type': 'application/json'
	}
}

rest.put(options);

PATCH Requests

//requires the resource URL and a message object as the arguments
rest.patch({url: '', json: {}})

rest.patch({url:'https://httpbin.org/patch', json: { hello: 'world'}})

//you can also create a separate object for the arguments and pass it to the API  
let options = {
	url: "https://httpbin.org/patch",
	json: { hello: 'world'},
}

rest.patch(options);

DELETE Requests

//requires the resource URL the argument
rest.delete({url: ''})

rest.delete({url:'https://httpbin.org/delete'})

//you can also create a separate object for the arguments and pass it to the API  
let options = {
	url: "https://httpbin.org/delete",
	headers: {
		'content-type': 'application/json'
	}
}

rest.delete(options);

MQTT APIs

Within the device template, you can use the MQTT APIs to interact with the MQTT connections.

Publish

To publish a message to an MQTT endpoint, you can use the following function.

//requires a payload object and a topic string as arguments
mqtt.publish(payload, topic)

let payload = {
    hello: 'world'
}

let topic = "testTopic"

mqtt.publish(payload, topic)

Resubscribe

To resubscribe to multiple topics use the following function.

//requires an array of topics as the argument
mqtt.resubscribe([topics])

mqtt.resubscribe([topic1, topic2, topic3])

Force Disconnect

To disconnect from all MQTT topics and close all connections, use the following function.

//no arguments are required for this function
mqtt.forceDisconect()

Force Connect

To connect to all previously connected MQTT connections, use the following function.

//no arguments are required for this function
mqtt.forceConect()
PreviousJob FunctionsNextGlob Functions

Last updated 2 years ago

Was this helpful?