Эта страница является
переводом страницы
CreateDriver. Перевод выполнен на 100%.
Creating your own driver
The example shows a process of creating a driver in iRidium Studio on the basis of AV & Custom Systems (HTTP) driver.
The documentation was updated on 20.8.2021
You can use AV & Custom Systems (HTTP) driver to process received informaton and/or to control equipment. To do it, you require Iridium Studio installed on a PC and any network analyzer (for example, WireShark). In the example we'll get data from https://openweathermap.org, parse them and display values in a panel project. Wireshark network analyzer is used to show that it is possible to parse data in cases when you do not know the format of sending requests to a resource (equipment) and the format of getting answers from it.
Getting Data from a Resource
1 Start a browser and go to the developer's website (in our example, it is https://openweathermap.org - a website providing information about weather in different locations). Choose an API request that will be executed to get data. Let's have a look at a request to get data about the current weather in London as an example.
A request of data to a resource will have the following format:
http://api.openweathermap.org/data/2.5/weather?q={city name}&units=metric&appid={API key},
- {city name} - the name of a city,
- {API key} - API authentication key.
You can read more detailed information on openweathermap official website.
2 Start Wireshark. Choose a device to capture (a network card) in Wireshark:
3 Choose a filter - by "http":
4 Make a request in a browser ( https://clck.ru/WBLfX ), then go to Wireshark, it must capture your traffic. Find a required request among captured packets and answer it. An answer to a request returns to the JSON format, it will be parsed and displayed in the project.
Working in iRidium studio
1 Start iRidium Studio and create four Labels, two will be used to show names of values and the other two will be used to display data about the air temperature and humidity.
2 Create AV & Custom Systems (HTTP) project driver. Open the driver parameters, find Host and enter the domain name / IP-address of a resource where a request will be sent (api.openweathermap.org/).
Read more detailed information in the description of AV & Custom Systems driver.
3 To send a request to a resource, use JS methods with the help of Script Editor in iRidium Studio. Create a new script in the Studio and paste the given code to get data from the website:
var DEVICE = IR.GetDevice("AV & Custom Systems (HTTP)");
function send()
{
DEVICE.Send(['GET,/data/2.5/weather?q=London&appid=81fb48bd46071175ab394e5f0e54092d']);
}
IR.AddListener(IR.EVENT_START, 0, send);
IR.AddListener(IR.EVENT_RECEIVE_TEXT, DEVICE, function(dataweather)
{
var result = JSON.Parse(dataweather);
IR.GetPage("Page 1").GetItem("Item 1").Text = result.main.temp ;
IR.GetPage("Page 1").GetItem("Item 2").Text = result.main.humidity;
IR.Log(dataweather);
});
4 To display current data about the weather all the time, you can create a request that will be sent automatically at a set interval. It can be done with the IR.SetInterval method:
IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetItem("Page 1"), function()
{
var ID = IR.SetInterval(5000, send); //5sec
});
IR.AddListener(IR.EVENT_ITEM_HIDE,IR.GetItem("Page 1"),function()
{
IR.ClearInterval(ID);
});
AV & Custom Systems (HTTP) does not keep an open connection, Online and Status tokens of the driver display the connection status the moment a request is sent, and an answer is received.