Apex Message Broker & Database (Redis)
Apex runs two Redis instances that can be used as message brokers or databases, the first one (User Application Redis) runs on the default port 6379 and the second one (System/Core Redis) is dedicated to Apex core applications and runs on port 7480.
System/Core Redis (Port 7480)
The System/Core Redis is an exclusive instance that runs on the port 7480
with which you can only read or subscribe to the data stored or published by the different apex core applications.
Available commands:
-
If you want to watch all the interaction between Redis and the apex core applications use:
- monitor
Format: redis-cli -p 7480 monitor
- monitor
-
If you want to receive the information generated by the apex core applications use:
-
psubscribe → Subscribe with a pattern if you don't know the complete channel.
Format: redis-cli -p 7480 psubscribe channel_pattern/*
-
subscribe → Subscribe with a complete channel.
Format: redis-cli -p 7480 subscribe channel
-
-
If you want to read the information stored by the apex core applications use:
- For lists lrange → Retrieve a certain number of elements in a list.
Format: redis-cli -p 7480 lrange list_name init_index final_index
- For hashes hgetall → Retrieve all elements in a hash.
Format: redis-cli -p 7480 hgetall hash_name
- For hashes hget → Retrieve only the value of the hash-key passed.
Format: redis-cli -p 7480 hgetall hash_name hash_key
- For keys get → Retrieve the value of the key passed.
Format: redis-cli -p 7480 get key
- For lists lrange → Retrieve a certain number of elements in a list.
Message Broker Usage
Monitor
You can subscribe to a special channel to watch all the interaction between Redis and the apex core applications, this is usefull to get message broker channels or database hashes, etc.
redis-cli -p 7480 monitor
# Example
redis-cli -p 7480 monitor | grep gps
1694194190.022920 [0 127.0.0.1:44566] "PUBLISH" "gps" "{\"time\":\"2023-09-08T17:29:50Z\",\"fix\":3,\"qlty\":1,\"hdop\":0.8,\"pdop\":1.0,\"vdop\":0.7,\"satused\":8,\"dec\":178.5,\"lat\":4.670165,\"lon\":-74.054296,\"alt\":2584.9,\"speed\":0.0,\"track\":0.0,\"raw_point\":{\"lat\":4.670225,\"lon\":-74.054209,\"alt\":2575.8,\"speed\":0.0,\"track\":173.0},\"processed\":1111277,\"errors\":0}"
1694194190.033946 [0 127.0.0.1:44566] "PUBLISH" "gps_speed_report" "0.000,0.80,1694194190"
1694194191.017595 [0 127.0.0.1:44566] "PUBLISH" "gps" "{\"time\":\"2023-09-08T17:29:51Z\",\"fix\":3,\"qlty\":1,\"hdop\":0.8,\"pdop\":1.1,\"vdop\":0.7,\"satused\":8,\"dec\":178.5,\"lat\":4.670165,\"lon\":-74.054296,\"alt\":2584.9,\"speed\":0.0,\"track\":0.0,\"raw_point\":{\"lat\":4.670225,\"lon\":-74.054209,\"alt\":2575.8,\"speed\":0.0,\"track\":173.0},\"processed\":1111281,\"errors\":0}"
Subscribe - Psubscribe
You can also subscribe some Redis channels to receive the information generated by the apex core applications.
Available channels to subscribe:
Channel | Description |
---|---|
accel/events | The channel that Acceleration/IMU module uses to notify its current state. |
interface/* | The channel that INTERFACE (I/O) module uses to notify its current state. |
bluetooth/notification/* | The channel that BLUETOOTH module uses to notify its current state. |
ecumonitor/* | The channel that ECU module uses to notify the different parameters. |
efs/notification/remove | The channel that EFS module uses to notify that a file has been removed. |
gps | The channel that GPS module uses to send position information. |
geofences/* | The channel that GEOFENCES module uses to notify changes in the current state. |
geofences/group/* | The channel that GEOFENCES module uses to notify changes in the current state for a specific group. |
leds/notification/* | The channel that LED module uses to notify when a led sequence has change. |
modem/notification/* | The channel that MDM module uses to notify changes in the current state. |
ndm/notification/* | The channel that NDM (Cipia - MDSM7 - People Counting) module uses to notify a new event. |
ndm/connection/* | The channel that NDM (Cipia - MDSM7 - People Counting) module uses to notify when a device is connected or disconnected. |
network/* | The channel that Network module uses to notify changes in network. |
onewire/notification/* | The channel that ONEWIRE module uses to notify changes in the current state. |
seco/notification/* | The channel that Safe Engine Cut Off module uses to notify changes in the current state. |
serial/notification/* | The channel that SERIAL module uses to notify changes in the current state. It also includes messages received via RS232. |
video/notification/* | The channel that VIDEO module uses to notify changes in the current state. |
window/notification/* | The channel that TIME_WINDOW module uses to notify changes in the current state. |
# Example subscribe
redis-cli -p 7480 subscribe gps
Reading messages... (press Ctrl-C to quit)
1) "message"
2) "gps_speed_report"
3) "0.019,0.61,1618502866"
1) "message"
2) "gps"
3) "{\"time\":\"2021-04-15T16:07:47Z\",\"fix\":3,\"qlty\":2,\"hdop\":0.63,\"pdop\":1.25,\"vdop\":1.08,\"satused\":15,\"dec\":0.00,\"lat\":25.783675,\"lon\":-80.293561,\"alt\":12.207,\"speed\":0.167,\"track\":346.74,\"raw_point\":{\"lat\":25.783578,\"lon\":-80.293516,\"alt\":23.328,\"speed\":0.019,\"track\":205.74},\"processed\":2135899,\"errors\":889}"
# Example psubscribe
redis-cli -p 7480 psubscribe interface/*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "interface/*"
3) (integer) 1
1) "pmessage"
2) "interface/*"
3) "interface/analog/BAT"
4) "3.988"
Database Usage
To consult data stored by the applications use lrange, hgetall, hget or get
Keys
Available keys to consult:
Key | Description |
---|---|
hotspot_mode | This key indicates if the wireless module has to be initialized in hotspot mode. |
network_interface | This key is used to indicate what is the current interface used for network connections. |
serial_rfid_last_id | Last RFID read. |
wifi_mode | This key indicates if the wireless module has to be initialized in wifi mode. |
# Example key get
redis-cli -p 7480 get wifi_mode
"off"
Lists
Available lists to consult:
List | Description |
---|---|
input_events | Last inputs events. |
ndm_fatigue_events | Last 25 clips generated from NDM module. |
psm_events | Last PSM events. |
video_clip_state | Last 25 clips generated from Video module. |
video_clips_queue | Video clips queue. |
watcher_inbox | Watcher incoming commands list. |
watcher_outbox | Watcher commands pending to be executed. |
# Example list lrange first 3 elements
redis-cli -p 7480 lrange psm_events 0 2
1) "HEARTBEAT,1692710998"
2) "I2C_WDT,1692710998"
3) "HEARTBEAT,1691183255"
# Example list lrange all elements use 0 -1 at the end
redis-cli -p 7480 lrange psm_events 0 -1
1) "HEARTBEAT,1692710998"
2) "I2C_WDT,1692710998"
3) "HEARTBEAT,1691183255"
4) "HEARTBEAT,1691146864"
5) "HEARTBEAT,1689265511"
6) "HEARTBEAT,1688647868"
7) "I2C_WDT,1688472508"
8) "PSM_ACTIVATED,1688165623"
9) "PSM_TIMEOUT,1688165208"
10) "PSM_ACTIVATED,1688165179"
11) "PSM_TIMEOUT,1688164556"
12) "PSM_ACTIVATED,1688164527"
13) "PSM_TIMEOUT,1688163903"
14) "PSM_ACTIVATED,1688163871"
15) "I2C_WDT,1688079050"
16) "PSM_ACTIVATED,1688079017"
17) "PWR,1688004360"
18) "PSM_ACTIVATED,1688004327"
19) "PWR,1687985473"
20) "PSM_TIMEOUT,1687984994"
21) "PSM_ACTIVATED,1687984961"
22) "PSM_TIMEOUT,1687984342"
23) "PSM_ACTIVATED,1687984305"
24) "I2C_WDT,1687983779"
25) "I2C_WDT,1687865837"
Hashes
Available Hashes to consult:
Hash | Description |
---|---|
accel_current_state | Current state of the Acceleration/IMU module. |
accel_configuration | Configuration used by the Acceleration/IMU module. |
bluetooth_current_state | Current state of the BLUETOOTH module. |
bluetooth_configuration | Configuration used by the BLUETOOTH module. |
bluetooth_discovered_devices | Bluetooth discovered devices. |
bluetooth_connected_devices | Bluetooth connected devices. |
counter_configuration | Configuration used by the COUNTERS module. |
counter_current_state | Current state of the COUNTERS module. |
ecumonitor_parameters | List of parameters read by the ecu-monitor application. |
ecumonitor_configuration | Configuration used by the ECU module. |
ecumonitor_current_state | Current state of the ECU module. |
efs_files | Hash with the newest and oldest event files. |
geofences_current_state | Current state of the GEOFENCES module |
geofences_* | Geofences namespace information, replace the * for the namespace. |
geofences_group_* | Geofences group information, replace the * for the group. |
gps_configuration | Configuration used by the GPS module. |
gps_current_state | Current state of the GPS module. |
interface_current_analog | Current state of all analog inputs. |
interface_current_output | Current state of all outputs. |
interface_current_input | Current state of all inputs. |
interface_current_state | Current state of the INTERFACE module. |
led_settings | Hash with configured led sequences. |
modem_configuration | Configuration used by the MDM module. |
modem_information | Current state of the MDM module. |
ndm_current_state | Hash where the NDM stores the devices (Cipia - MDSM7 - People Counting) state. |
ndm_pc_counter | Hash with the People counter summary. |
ndm_pc_report | Hash with the People counter summary that is updated when a report is generated by the camera. |
ndm_pc_realtime_counter | Hash with the People counter summary that is updated when an event is generated by the camera. |
onewire_last_devices | Last devices read by the ONEWIRE module. |
onewire_current_state | Current state of the ONEWIRE module. |
seco_current_state | Safe Engine Cut Off current state. |
serial_configuration | Global configuration used by the SERIAL module. |
serial_cnsl_cfg | Configuration used by the SERIAL module for the Console mode. |
serial_fatigue_s_state | Current state of the Fatigue Sensor. |
serial_fatigue_s_cfg | Configuration used by the SERIAL module for the Fatigue Sensor mode. |
serial_fuel_sensor_state | Current state of the Fuel Sensor. |
serial_fuel_sensor_config | Configuration used by the SERIAL module for the Fuel Sensor mode. |
serial_modem_state | Current state of the Serial Modem. |
serial_mdt_cfg | Configuration used by the SERIAL module for the MDT mode. |
serial_rfid_auth_list | List of the RFID authorized ID's |
tracking_configuration | Tracking configuration used by the GPS module. |
video_current_state | Current state of VIDEO module. |
video_history_* | Hash with the video history record. Ranges are stored by day in json format. Change the * for the camera name. |
video_device_state | Hash with the connection state of the devices controlled by the VIDEO module. |
windows_list | Hash with the current time windows configured. |
watcher_configuration | Configuration used by the WATCHER module. |
# Example HGETALL to get all elements
redis-cli -p 7480 hgetall interface_current_analog
1) "BAT"
2) "3.988"
3) "AN1"
4) "0"
5) "AN2"
6) "0"
7) "DAN"
8) "0"
# Example HGET to get one element
redis-cli -p 7480 hget interface_current_analog BAT
"3.988"
User Application Redis (Port 6379)
The user application Redis instance that runs on the default port 6379
, have full permissions for user syrus4g, allowing you to use this instance for your custom applications.
Message Broker Usage
Monitor
You can subscribe to a special channel to watch all the interaction between Redis and the apex core applications, this is usefull to get message broker channels or database hashes, etc.
redis-cli monitor
PUBLISH - SUBSCRIBE
To publish messages and receive those messages you can use the following commands:
# Example
redis-cli publish test_channels/first_channel "Hello World"
redis-cli psubscribe test_channels/*
Reading messages... (press Ctrl-C to quit)
1) "psubscribe"
2) "test_channels/*"
3) (integer) 1
1) "pmessage"
2) "test_channels/*"
3) "test_channels/first_channel"
4) "Hello World"
Database Usage
To store and read data you can use the following commands, for more information about this go to Redis official site.
SET - GET
# Example
redis-cli set mykey "hello world"
OK
redis-cli get mykey
"hello world"
HSET - HGET
# Example
redis-cli hset myhash first_element "hello world"
(integer) 1
redis-cli hget myhash first_element
"hello world"
LIST (LPUSH - LPOP)
# Example
redis-cli lpush mylist "world"
(integer) 1
redis-cli lpush mylist "hello"
(integer) 2
redis-cli lpop mylist
"hello"
Many other functions that are not described here can be found at Redis official site.
Updated 4 days ago