Latest Version: 1.0.0
This library provides an interface to the STN1110 Multiprotocol OBD-II to UART Interpreter.
You can view the library’s source code on GitHub. Click here to see information on other versions of this library.
To add this library to your project, add #require "STN1110.class.nut:1.0.0"
to the top of your device code
Two classes are implemented for interacting with the STN1110 over UART.
An example utilizing VehicleInterface and the Plotly library is provided. It logs several vehicle parameters over time and generates a plotly graph of their values.
Short examples for each class are provided below.
#require "STN1110.class.nut:1.0.0"
car <- VehicleInterface(hardware.uart57);
// Logs vehicle speed once per second
car.subscribe(car.VEHICLE_SPEED, function(result) {
if ("err" in result) {
server.error("Error getting vehicle speed");
return;
}
server.log("Current speed: " + result["msg"] + "km/h");
}, 1);
stn1110 <- STN1110(hardware.uart57);
stn1110.execute("AT@1", 1, function(result) {
// AT@1 command returns device description string
if ("err" in result) {
server.error("Error executing command");
return;
}
server.log("Device description: " + result["msg"]);
});
To instantiate the VehicleInterface class, pass in the imp UART bus that the STN1110 is connected to. The UART will be reconfigured by the constructor for communication with the STN1110. This is a blocking call that will return when the STN1110 interface is ready to use. This method may throw an exception if initializing the device fails or times out. The optional baud parameter can be used for initial connection if the STN1110 has a baud rate other than the default 9600 stored in its EEPROM.
Reads a PID once and executes callback with the resulting data. If the PID is in the list of supported PIDs, the callback will be called with a single value in the correct units. If the PID is not supported, the callback will be called with a byte array containing the raw result of the request.
Reads a PID every period seconds and executes callback with the resulting data. If the PID is in the list of supported PIDs, the callback will be called with a single value in the correct units. If the PID is not supported, the callback will be called with a byte array containing the raw result of the request.
Unsubscribes the callback, if any, for PID pid and stops requesting the PID.
The engine's RPM in units RPM.
Get the vehicle speed in units km/h.
The throttle position as a percentage.
The engine coolant temperature in degrees Celsius.
The fuel pressure in kPa.
The intake air temperature in degrees Celsius.
The runtime since engine start in minutes.
To instantiate the class, pass in the imp UART bus that the STN1110 is connected to. The UART will be reconfigured by the constructor for communication with the STN1110. This is a blocking call that will return when the STN1110 interface is ready to use. This method may throw an exception if initializing the device fails or times out. The optional baud parameter can be used for initial connection if the STN1110 has a baud rate other than the default 9600 stored in its EEPROM.
Executes the command string command with the timeout timeout in seconds and calls callback with the result. The callback is called with one parameter: a table containing either an err key or a msg key. If the err key is present in the table, an error occured during command execution and the corresponding value describes the error. If the err key is not present in the table, the msg value will contain the output of the command.
Performs a soft reset of the STN1110. This is a blocking call that will return when the STN1110 interface is ready to use. This method may throw an exception if initializing the device fails or times out.
Sets the baud rate to baud. This is a blocking call. When it returns, the STN1110 is now operating at the specified baud rate or an exception will have been thrown. Exceptions will be thrown if commands are currently executing, if the baud rate is deemed invalid by the STN1110, or if another error occurs while setting the baud rate.
Returns the baud rate at which the UART interface is currently operating.
Returns the version string of the ELM emulator provided by the STN1110 on reset.
Pass a callback function, callback, to be executed if an error occurs after initialization and no PID callbacks are registered to receive the error.
The Electric Imp Dev Center documents the latest version of the library. For past versions, please see the Electric Imp public GitHub repos listed below.
Version | Source Code | Notes |
---|---|---|
1.0.0 | GitHub | Initial release |
The STN1110 library is licensed under the MIT License.