Drivers for developers
What a driver is, where it runs and how a reading travels from a device to a sensor.
Cette page n’est pas encore traduite. Tu lis l’original.
A driver connects one kind of device to Total.js IoT Platform. It is a single file that you install in Drivers (see Drivers). This section explains how to write one.
What a driver does
- It describes the device: name, manufacturer, icon and the values it measures. Each value is an output, and every device of the driver gets one sensor for each output.
- It receives data. Usually it creates an HTTP address on the stream where the devices post their readings.
- It processes each message and sends the values to its outputs. The platform stores them, keeps the statistics and shows them in the app.
- Optionally it has settings for each device, options for the whole driver, commands, its own database tables and alerts.
Where a driver runs
Admin stores the driver in the database. The Stream app loads every driver and every device from the database and runs them in a FlowStream: each driver is a component, and each device is an instance of that component. The stream reloads drivers and devices every three minutes, so a new or changed driver works within three minutes of saving it, without a restart.
The path of a reading
- A device posts JSON to the address of its driver on the stream, for example
POST /demoweather/. - The route of the driver checks the data and finds the instance of the device by its identifier.
- The route passes the data to
instance.messageof that device. instance.messagesends each value to an output withinstance.newmessage(value).send('temperature').- The stream writes the last value and the statistics to the database. The value appears in Sensors and on the map.
What to read next
- Your first driver builds and tests a complete driver.
- The driver file explains the parts of the file.
- Driver reference and Instance reference list every property and function.