Using POST /data_source/mqtt
The first step to define an input is to use the POST request of the endpoint /data_source/mqtt
Registering a data_source through MQTT
Using a reserved word
If you chose a reserved word in your optimization model because you are working with energy applications, you can register your input data in the following way:
- From the API, you find out which is the data model for entering a photovoltaic registry. Inside of it you choose the one that you need. If you are interested in registering an input for the total PV power for example, you choose P_PV. Because we want to enter meta data at the same time, we choose "meta" as well.
{ "photovoltaic":{ "P_PV":{ "mqtt":{ "host":"ip_address or name_host", "topic":"name_topic_input_data", "qos":1 } }, "meta":{ "PV_Inv_Max_Power":1000 # Entered in Watt [W] } } }
- Then send this data to the /data_source/mqtt endpoint
curl --request POST \ --url http://ip_address:8080/v1/data_source/mqtt \ --header 'Cache-Control: no-cache' \ --header 'Content-Type: application/json' \ --data '{\r\n "photovoltaic":{\r\n "P_PV":{\r\n "mqtt":{\r\n "host":"ip_address or name_host",\r\n "topic":"name_topic_input_data",\r\n "qos":1\r\n }\r\n },\r\n "meta":{\r\n "PV_Inv_Max_Power":1000 \r\n }\r\n }\r\n}'
Using a custom word
If you don't want to use any reserved word, you can register your input data in the following way:
- From the API, you find out which is the data model for entering a custom registry. Inside of it you choose the one that you need. If you are interested in registering an input for the total PV power with the name "Power_Photovoltaic", you can enter this information. The example shows a list of input values, if you have more than one custom inputs.
{ "generic":[ { "name":"Power_Photovoltaic", "mqtt":{ "host":"ip_address or name_host", "topic":"name_topic_input_data", "qos":1 } }, { "name":"custom_name", "mqtt":{ "host":"string", "topic":"string", "qos":1 } } ] }
- Then send this data to the /data_source/mqtt endpoint
curl --request POST \ --url http://ip_address:8080/v1/data_source/mqtt \ --header 'Cache-Control: no-cache' \ --header 'Content-Type: application/json' \ --data '{\r\n "generic":[\r\n {\r\n "name":"Power_Photovoltaic",\r\n "mqtt":{\r\n "host":"ip_address or name_host",\r\n "topic":"name_topic_input_data",\r\n "qos":1\r\n }\r\n },\r\n {\r\n "name":"custom_name",\r\n "mqtt":{\r\n "host":"string",\r\n "topic":"string",\r\n "qos":1\r\n }\r\n }\r\n\r\n ]\r\n}'
Sending data through MQTT
For sending data in MQTT, you have to use SenML standard.
An example of it is:
[{"n":"P_PV", "v":1000.0, "u":"W", "t": 1540811392.0 }]
where the time is expressed in seconds.