Skip to content

Data Connectors

Name Input Params Return Data Description
resiot_dc_push String, String, String String
resiot_sql_query String, String, String String
resiot_http_push_custom String, String, String, String String

resiot_dc_push(String, String, String)

ResIOT allows you to push custom data over your pusher connectors. Unless you know what you're doing, you should avoid using this function as ResIOT takes care of pushing node transmissions and gateway data to your connectors automatically (except for SQL pushers).
Please notice currently, you can push custom data only to Mosquitto servers, Http pushers, Websockets, MongoDB, SQL databases and Amazon AWS IOT. There is no support for Microsoft Azure yet.

This function requires the Hex ID of your connector and a varying number of parameters depending on the nature of the connector.

Here's how to push data to your connectors.

Mosquitto Brokers, Amazon AWS IOT

You need to pass two additional parameters to the function: a Topic and a Data string parameters.

Websockets and HTTP pushers

These connectors only need a Data string parameter.

MongoDB

This connector needs only one serializable (JSON) string parameter. An error will be thrown if the string is not a valid JSON.

SQL Database Pushers

This connector accepts an unlimited number of parameters, where the first one is the query you wish to run, and the others are the query parameters which will replace the query placeholders. Due to the different nature of the database drivers used by the ResIOT engine, each type of database has different placeholders to be used in their queries. Please refer to the SQL Database Pusher.

Your public websocket

If you want to push data to your public websocket, leave the HexId field empty ( "" ) and pass an additional Data string parameter.
The data pushed will be wrapped in a JSON inside a "data" field, along with a "CommType" field with value "comm_push" and the "DT" current time.

Example
Error = resiot_dc_push(HexId, Topic, Payload)
Input Parameters
 - HexId(string): The HexId of the Data Connector. If left empty, a CommType "comm_push" message will be sent to your public websocket connector.
 - Topic(string): The payload of the message (if needed).
 - Payload(string): The message body sent to the Data Connector.
Returns
 - Error (String): The function returns an empty string if no error occurred. If an error occurred, the string will contain a description of what went wrong.

HexId = "636f6e323732"          -- The HexId of the Data Connector. If left empty, a CommType "comm_push" message will be sent to your public websocket connector
Topic = "resiot/test"           -- The payload of the message (if needed)
Payload = '{"payload":"test"}'  -- The message body sent to the Data Connector
err = resiot_dc_push(HexId, Topic, Payload) --this works for amazon aws / mqtt pushers, fails for http pushers as no topic is required
if err ~= "" then
    -- error 
    resiot_debug(err)
end

err = resiot_dc_push(HexId, Payload) -- this works for http pushers, and returns an error for mqtt connecotrs
if err ~= "" then
    -- error 
    resiot_debug(err)
end

Return to index


resiot_sql_query(String, String, String)

This function executes SELECT queries on the selected SQL Pusher and returns a json containing records informations.
After the first connector parameter, this function accepts an unlimited number of parameters, where the first one is the query you wish to run, and the others are the query parameters which will replace the query placeholders. Due to the different nature of the database drivers used by the ResIOT engine, each type of database has different placeholders to be used in their queries. Please refer to the SQL Database Pusher.

Example
ResultJson, Error = resiot_sql_query(HexId, Query, Params)
Input Parameters
 - HexId(string): The HexId of the SQL Pusher.
 - Query(string): The SELECT query to execute.
 - Params(string/int): An unlimited number of parameters which will replace query placeholders.
Returns
 - ResultJson (String): The function returns the query result in json format and an error. If an error occurred, the string will contain a description of what went wrong. ResultJson has this format: {"datacount": int, "fieldscount": int, "fields": []string, "data": []string}.
"datacount" contains how many records have been found, if its value is zero the json field "data" is omitted.
"fieldscount" contains how many columns each record has returned, it's useful when using queries like "SELECT * FROM...", if its value is zero the json field "fields" is omitted.
"fields" contains an array of column names.
"data" contains an array of jsons, each json contains the fields listed in ResultJson "fields" with their value for that record.

HexId = "636f6e333339"          -- The HexId of the SQL Pusher
Query = "select * from films"   -- The query to execute
ResultJson, err = resiot_sql_query(HexId, Query)
resiot_debug(ResultJson)
--[[ example of ResultJson
    {
        "datacount":2,
        "fieldscount":6,
        "fields":["code","title","did","date_prod","kind","len"],
        "data":[
            "{\"code\":\"Z2cgICA=\",\"date_prod\":null,\"did\":0,\"kind\":null,\"len\":null,\"title\":\"gg\"}",
            "{\"code\":\"Z2cxICA=\",\"date_prod\":null,\"did\":0,\"kind\":null,\"len\":null,\"title\":\"gg1\"}"
        ]
    }
]]
if err ~= "" then
    -- error 
    resiot_debug(err)
end


HexId = "636f6e333339"                                      -- The HexId of the SQL Pusher
Query = "select * from films where did = ? and title = ?"   -- The query to execute with MySQL placeholders 
                                                            -- (please use the correct placeholders based on your DB type)
Param1 = 0                                                  -- The first optional parameter
Param2 = "gg1"                                              -- The second optional parameter
ResultJson, err = resiot_sql_query(HexId, Query, Param1, Param2)
resiot_debug(ResultJson)
--[[ example of ResultJson
    {
        "datacount":1,
        "fieldscount":6,
        "fields":["code","title","did","date_prod","kind","len"],
        "data":[
            "{\"code\":\"Z2cxICA=\",\"date_prod\":null,\"did\":0,\"kind\":null,\"len\":null,\"title\":\"gg1\"}"
        ]
    }
]]
if err ~= "" then
    -- error 
    resiot_debug(err)
end


HexId = "636f6e333339"                                      -- The HexId of the SQL Pusher
Query = "select * from films where did = ? and title = ?"   -- The query to execute with MySQL placeholders 
                                                            -- (please use the correct placeholders based on your DB type)
Param1 = 0                                                  -- The first optional parameter
Param2 = "unregistered title"                               -- The second optional parameter
ResultJson, err = resiot_sql_query(HexId, Query, Param1, Param2)
resiot_debug(ResultJson)
--[[ example of ResultJson with 0 records found
    {
        "datacount":0,
        "fieldscount":0
    }
]]
if err ~= "" then
    -- error 
    resiot_debug(err)
end

Return to index


resiot_http_push_custom(String, String, String, String)

ResIOT allows you to push custom data over your HTTP pusher connectors with custom headers. If you use this function, Auth headers configured on your pusher will be ignored.

Example
Error = resiot_http_push_custom(HexId, Payload, ExtraHeaderName, ExtraHeaderValue)
Input Parameters
 - HexId(string): The HexId of the HTTP Pusher.
 - Payload(string): The message body sent to the HTTP Pusher.
 - ExtraHeaderName(string): The header name you want to send, it must be followed by an ExtraHeaderValue. You can add as many pairs of ExtraHeaderName-ExtraHeaderValue as you want. If a pair is incomplete an error will be returned.
 - ExtraHeaderValue(string): The header value of the header specified in the previous ExtraHeaderName.
Returns
 - Error (String): The function returns an empty string if no error occurred. If an error occurred, the string will contain a description of what went wrong.

HexId = "636f6e323732"          -- The HexId of the HTTP Pusher
Payload = '{"payload":"test"}'  -- The message body sent to the HTTP Pusher
ExtraHeaderName1 = ''           -- The header name
ExtraHeaderValue1 = ''          -- The header value
ExtraHeaderName2 = ''           -- The header name
ExtraHeaderValue2 = ''          -- The header value
err = resiot_http_push_custom(HexId, Payload, ExtraHeaderName1, ExtraHeaderValue1, ExtraHeaderName2, ExtraHeaderValue2)
if err ~= "" then
    -- error 
    resiot_debug(err)
end

Return to index