GPIO over SMS example (Python): Różnice pomiędzy wersjami

Z Elproma Wiki Knowledge Base
Skocz do: nawigacja, szukaj
Linia 1: Linia 1:
In this page we are describing the example of the remote GPIO over SMS function in RBMTX-Lite-IO router series.
In this page we are describing the example of ''GPIO over SMS'' function in RBMTX-Lite-IO router variant. The purpose of this example is to add extra logic to the device to control inputs and outputs remotely.


==Description==


Router is based on OpenWrt system so you can add scripts or programs to device. One of the simplest, powerful and most popular programming language is Python. RBMTX-Lite supports Python version 3.9.12 so you can easily write, upload and run your scripts on the device. Here is the description of Python script whose main task is to receive/send SMS messages and control GPIO lines of the router.
==Python script==
Script can be downloaded here:
smbus module is imported in the script. Thanks to it you can configure and communicate with GPIO over i2c interface.
To read the GPIO state use read_byte_data() function. Router will response with six bits corresponding to the actual GPIO states (OUT3, OUT2, OUT1, IN3, IN2 and IN1).
To change the state of a given output use write_byte() function. For example, if all outputs and inputs are in a low state, if you send
bus.write_byte(i2c_chip_address , int('100000',2))
you will set OUT3 to high state.


[[File:example_gpio_sms_py.png|400px]]
[[File:example_gpio_sms_py.png|400px]]

Wersja z 13:30, 8 gru 2022

In this page we are describing the example of GPIO over SMS function in RBMTX-Lite-IO router variant. The purpose of this example is to add extra logic to the device to control inputs and outputs remotely.

Description

Router is based on OpenWrt system so you can add scripts or programs to device. One of the simplest, powerful and most popular programming language is Python. RBMTX-Lite supports Python version 3.9.12 so you can easily write, upload and run your scripts on the device. Here is the description of Python script whose main task is to receive/send SMS messages and control GPIO lines of the router.

Python script

Script can be downloaded here:

smbus module is imported in the script. Thanks to it you can configure and communicate with GPIO over i2c interface. To read the GPIO state use read_byte_data() function. Router will response with six bits corresponding to the actual GPIO states (OUT3, OUT2, OUT1, IN3, IN2 and IN1).

To change the state of a given output use write_byte() function. For example, if all outputs and inputs are in a low state, if you send bus.write_byte(i2c_chip_address , int('100000',2)) you will set OUT3 to high state.

Plik:Example gpio sms py.png