├── boards ├── README.md ├── nrf52_dongle │ ├── softdevice_s132_nRF52_2.0.0.bin │ ├── images │ │ ├── dongle.png │ │ ├── adapter.png │ │ ├── back_swdio.png │ │ ├── components.png │ │ ├── default_map.png │ │ ├── pogo-pin adapter.jpg │ │ └── pogo-pin 0.5mm x 16.35mm.png │ └── 3d_models │ │ └── needls_support.stl ├── nrf52_sensortag │ ├── images │ │ ├── PCB.png │ │ ├── mounted.png │ │ ├── sensor_tag.png │ │ ├── module_size.png │ │ └── schematics_pinout.png │ └── pcb │ │ ├── nRF52_sensortag_gerbers.zip │ │ └── .gitignore ├── nrf52_sensortag.h ├── nrf52832_rovarm.h ├── nrf52_dongle.h ├── nrf52_buttons.h ├── custom840.h └── pca10059.h ├── .gitignore ├── raspi ├── .gitignore ├── heat │ ├── .gitignore │ ├── config.json │ ├── config_WassDell.json │ ├── config_mano.json │ ├── mqtt.py │ ├── cfg.py │ └── heat.py ├── home_status │ ├── .gitignore │ ├── config.json │ ├── config_WassDell.json │ ├── config_mano.json │ ├── mqtt.py │ └── cfg.py ├── bathroom │ ├── .gitignore │ ├── config.json │ ├── config_WassDell.json │ ├── config_mano.json │ ├── mqtt.py │ └── cfg.py ├── wemo │ ├── .gitignore │ ├── config.json │ ├── cfg.py │ └── mqtt.py ├── esp32 │ ├── .gitignore │ ├── config.json │ ├── config_WassDell.json │ ├── config_mano.json │ ├── cfg.py │ └── mqtt.py ├── ruler │ ├── .gitignore │ ├── config.json │ ├── config_WassDell.json │ ├── config_mano.json │ ├── cfg.py │ └── ruler.py ├── rf_stm32 │ ├── .gitignore │ ├── config.json │ ├── config_mano.json │ ├── config_WassDell.json │ ├── rf_uart.py │ ├── cfg.py │ └── mqtt.py ├── rf_uart │ ├── .gitignore │ ├── mesh_controller.service │ ├── config.json │ ├── config_rfserv.json │ ├── config_webserv.json │ ├── config_WassDell.json │ ├── rf_uart.py │ ├── uart_failure.md │ ├── mqtt.py │ └── cfg.py ├── influx │ ├── .gitignore │ ├── export_1y.sh │ ├── export_csv.sh │ ├── backup.sh │ ├── config.json │ ├── config_WassDell.json │ ├── cfg.py │ ├── mqtt.py │ └── readme.md ├── conbee │ ├── .gitignore │ ├── readme.md │ ├── config.json │ ├── config_WassDell.json │ ├── output.log │ ├── sensors_notifications.json │ ├── mqtt.py │ └── cfg.py ├── requirements.txt ├── leds_panel │ ├── config_WassDell.json │ ├── cfg.py │ ├── mqtt.py │ └── leds_panel.py ├── raspi_run.sh ├── milight │ ├── config.json │ ├── cfg.py │ └── milight_gateway.py └── hue │ └── hue_config.json ├── applications ├── 01_sensortag │ ├── .gitignore │ ├── README.md │ └── esb_low_power_ptx_gcc_nrf52.ld ├── 02_accell_tag │ ├── .gitignore │ ├── esb_low_power_ptx_gcc_nrf52.ld │ └── debug.jdebug.user ├── 03_buttons │ ├── .gitignore │ ├── esb_low_power_ptx_gcc_nrf52.ld │ └── debug.jdebug.user ├── 04_uart_dongle │ ├── .gitignore │ └── esb_ptx_prx_gcc_nrf52.ld ├── 06_bldc_52832 │ ├── .gitignore │ └── esb_ptx_prx_gcc_nrf52.ld ├── 08_usb_dongle │ ├── .gitignore │ ├── nRF52840_debug.jdebug.user │ ├── openthread_nrf52840.ld │ └── openthread_nrf52840_bootloader.ld ├── 10_sensored_bldc │ ├── .gitignore │ ├── main.cpp │ ├── openthread_nrf52840.ld │ └── openthread_nrf52840_bootloader.ld ├── 05_rotary_decoder │ ├── .gitignore │ ├── readme.md │ └── esb_ptx_prx_gcc_nrf52.ld ├── 09_usb_dongle_cpp │ ├── .gitignore │ ├── openthread_nrf52840.ld │ └── openthread_nrf52840_bootloader.ld ├── uicr_map.json └── uicr_user_defines.h ├── tools ├── private.bat ├── .gitignore ├── on.bat ├── off.bat ├── read.bat ├── write.bat ├── public.bat ├── settings.bat ├── package.bat └── cfg.py ├── images ├── mesh.png ├── packet.png ├── pylink.png ├── buttons.png ├── nrf_mqtt.gif ├── protocol.png ├── alive-json.png ├── motion_tag.png ├── nodes.json.png ├── nrf_serial.gif ├── rf_encoder.png ├── bldc_control.png ├── cmsis-wizard.png ├── pogo-versions.jpg ├── nRF52-features.png ├── alive-trace-route.png ├── grafana-dashboard.png ├── nRF52832_sensortag.png ├── 2018-05-13_14h46_20.png ├── nRF52840-dongle-debug.png ├── nrf52840-usb-dongle.png └── discourse.svg ├── nodes-server.sh ├── drivers ├── battery.h ├── twi.h ├── clocks.h ├── app_ser.h ├── compare.h ├── bldc.h ├── usb_print.h ├── timestamp.h ├── strmap.hpp ├── usb_print.hpp ├── mpu6050.h ├── max44009.h ├── usb_print.cpp ├── bldc.hpp ├── strmap.cpp ├── utils.h ├── timestamp.c ├── compare.c ├── twi.c ├── clocks.c ├── mesh.h └── max44009.c ├── run_services.sh ├── .gitmodules └── .vscode ├── settings.json └── c_cpp_properties.json /boards/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.tmp 3 | -------------------------------------------------------------------------------- /raspi/.gitignore: -------------------------------------------------------------------------------- 1 | .python_hue 2 | -------------------------------------------------------------------------------- /raspi/heat/.gitignore: -------------------------------------------------------------------------------- 1 | heat.log 2 | -------------------------------------------------------------------------------- /raspi/home_status/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | -------------------------------------------------------------------------------- /raspi/bathroom/.gitignore: -------------------------------------------------------------------------------- 1 | bathroom.log 2 | -------------------------------------------------------------------------------- /applications/01_sensortag/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /applications/02_accell_tag/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /applications/03_buttons/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | -------------------------------------------------------------------------------- /raspi/wemo/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /boards/nrf52_dongle/softdevice_s132_nRF52_2.0.0.bin: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /raspi/esp32/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.pyc 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /raspi/ruler/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.log 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /applications/01_sensortag/README.md: -------------------------------------------------------------------------------- 1 | nRF52 Sensor Tag 2 | = 3 | -------------------------------------------------------------------------------- /raspi/rf_stm32/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.pyc 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /raspi/rf_uart/.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.pyc 3 | __pycache__ 4 | -------------------------------------------------------------------------------- /tools/private.bat: -------------------------------------------------------------------------------- 1 | nrfutil keys generate %VAULT%\nrf52_priv.pem -------------------------------------------------------------------------------- /raspi/influx/.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | influx.log 4 | -------------------------------------------------------------------------------- /applications/04_uart_dongle/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /applications/06_bldc_52832/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /applications/08_usb_dongle/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /applications/10_sensored_bldc/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /applications/05_rotary_decoder/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /applications/09_usb_dongle_cpp/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | debug.jdebug.user 3 | -------------------------------------------------------------------------------- /tools/.gitignore: -------------------------------------------------------------------------------- 1 | nrf52_public.c 2 | app_dfu_package.zip 3 | settings.hex 4 | -------------------------------------------------------------------------------- /tools/on.bat: -------------------------------------------------------------------------------- 1 | cd /D "%~dp0" 2 | python -c "from uicr import *;jlink.power_on()" 3 | -------------------------------------------------------------------------------- /images/mesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/mesh.png -------------------------------------------------------------------------------- /images/packet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/packet.png -------------------------------------------------------------------------------- /images/pylink.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/pylink.png -------------------------------------------------------------------------------- /tools/off.bat: -------------------------------------------------------------------------------- 1 | cd /D "%~dp0" 2 | python -c "from uicr import *;jlink.power_off()" 3 | -------------------------------------------------------------------------------- /images/buttons.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/buttons.png -------------------------------------------------------------------------------- /images/nrf_mqtt.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nrf_mqtt.gif -------------------------------------------------------------------------------- /images/protocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/protocol.png -------------------------------------------------------------------------------- /images/alive-json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/alive-json.png -------------------------------------------------------------------------------- /images/motion_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/motion_tag.png -------------------------------------------------------------------------------- /images/nodes.json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nodes.json.png -------------------------------------------------------------------------------- /images/nrf_serial.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nrf_serial.gif -------------------------------------------------------------------------------- /images/rf_encoder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/rf_encoder.png -------------------------------------------------------------------------------- /tools/read.bat: -------------------------------------------------------------------------------- 1 | C:\Python27\python.exe -c "from uicr import *;start();read_id();read_config()" 2 | -------------------------------------------------------------------------------- /images/bldc_control.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/bldc_control.png -------------------------------------------------------------------------------- /images/cmsis-wizard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/cmsis-wizard.png -------------------------------------------------------------------------------- /images/pogo-versions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/pogo-versions.jpg -------------------------------------------------------------------------------- /tools/write.bat: -------------------------------------------------------------------------------- 1 | C:\Python27\python.exe -c "from uicr import *;start();read_id();write_config()" 2 | -------------------------------------------------------------------------------- /images/nRF52-features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nRF52-features.png -------------------------------------------------------------------------------- /tools/public.bat: -------------------------------------------------------------------------------- 1 | nrfutil keys display --key pk --format code %VAULT%\nrf52_priv.pem --out_file nrf52_public.c -------------------------------------------------------------------------------- /images/alive-trace-route.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/alive-trace-route.png -------------------------------------------------------------------------------- /images/grafana-dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/grafana-dashboard.png -------------------------------------------------------------------------------- /images/nRF52832_sensortag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nRF52832_sensortag.png -------------------------------------------------------------------------------- /images/2018-05-13_14h46_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/2018-05-13_14h46_20.png -------------------------------------------------------------------------------- /images/nRF52840-dongle-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nRF52840-dongle-debug.png -------------------------------------------------------------------------------- /images/nrf52840-usb-dongle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/images/nrf52840-usb-dongle.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/dongle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/dongle.png -------------------------------------------------------------------------------- /boards/nrf52_sensortag/images/PCB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/images/PCB.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/adapter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/adapter.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/back_swdio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/back_swdio.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/components.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/components.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/default_map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/default_map.png -------------------------------------------------------------------------------- /boards/nrf52_sensortag/images/mounted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/images/mounted.png -------------------------------------------------------------------------------- /boards/nrf52_sensortag/images/sensor_tag.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/images/sensor_tag.png -------------------------------------------------------------------------------- /raspi/conbee/.gitignore: -------------------------------------------------------------------------------- 1 | conbee_sensors.json 2 | out_conbee.log 3 | hue_get.json 4 | hue_config.json 5 | hue_sensors.json 6 | hue_rules.json 7 | -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/pogo-pin adapter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/pogo-pin adapter.jpg -------------------------------------------------------------------------------- /boards/nrf52_sensortag/images/module_size.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/images/module_size.png -------------------------------------------------------------------------------- /boards/nrf52_dongle/3d_models/needls_support.stl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/3d_models/needls_support.stl -------------------------------------------------------------------------------- /boards/nrf52_sensortag/images/schematics_pinout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/images/schematics_pinout.png -------------------------------------------------------------------------------- /boards/nrf52_sensortag/pcb/nRF52_sensortag_gerbers.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_sensortag/pcb/nRF52_sensortag_gerbers.zip -------------------------------------------------------------------------------- /boards/nrf52_dongle/images/pogo-pin 0.5mm x 16.35mm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nRFMesh/nRF52_Mesh/HEAD/boards/nrf52_dongle/images/pogo-pin 0.5mm x 16.35mm.png -------------------------------------------------------------------------------- /nodes-server.sh: -------------------------------------------------------------------------------- 1 | docker run --name nodes-server -v /home/pi/nRF52_Mesh/nodes.json:/usr/share/nginx/html/nodes.json:ro -p 8080:80 -d --restart unless-stopped nginx 2 | -------------------------------------------------------------------------------- /raspi/influx/export_1y.sh: -------------------------------------------------------------------------------- 1 | influx -database 'meshNodes' -execute 'SELECT "temperature" FROM "node78" WHERE time > now() - 1y' -format 'csv' > /home/pi/share/$(date +%F)_influx_backup.csv 2 | -------------------------------------------------------------------------------- /raspi/requirements.txt: -------------------------------------------------------------------------------- 1 | vectors 2 | influxdb 3 | paho-mqtt 4 | milight 5 | phue 6 | git+https://github.com/iancmcc/ouimeaux.git 7 | websockets 8 | requests 9 | serial 10 | colour 11 | -------------------------------------------------------------------------------- /drivers/battery.h: -------------------------------------------------------------------------------- 1 | #ifndef __BATTERY_H__ 2 | #define __BATTERY_H__ 3 | 4 | #include 5 | 6 | void battery_init(); 7 | 8 | uint16_t get_battery(); 9 | 10 | 11 | #endif /*__BATTERY_H__*/ 12 | -------------------------------------------------------------------------------- /tools/settings.bat: -------------------------------------------------------------------------------- 1 | nrfutil settings generate --family NRF52 --application ..\applications\nrf52_sensortag\_build\nrf52832_xxaa.hex --application-version 3 --bootloader-version 2 --bl-settings-version 1 settings.hex -------------------------------------------------------------------------------- /tools/package.bat: -------------------------------------------------------------------------------- 1 | nrfutil pkg generate --hw-version 52 --sd-req 0x80 --application-version 3 --application ..\applications\nrf52_sensortag\_build\nrf52832_xxaa.hex --key-file "%VAULT%\nrf52_priv.pem" app_dfu_package.zip -------------------------------------------------------------------------------- /boards/nrf52_sensortag/pcb/.gitignore: -------------------------------------------------------------------------------- 1 | *.lck 2 | *.b#1 3 | *.b#2 4 | *.b#3 5 | *.b#4 6 | *.b#5 7 | *.b#6 8 | *.b#7 9 | *.b#8 10 | *.b#9 11 | *.s#1 12 | *.s#2 13 | *.s#3 14 | *.s#4 15 | *.s#5 16 | *.s#6 17 | *.s#7 18 | *.s#8 19 | *.s#9 20 | -------------------------------------------------------------------------------- /raspi/influx/export_csv.sh: -------------------------------------------------------------------------------- 1 | influx -database 'meshNodes' -execute 'SELECT "temperature" FROM "node78" WHERE time > '\''2017-01-01'\'' and time < '\''2017-12-12T23:59:59Z'\''' -format 'csv' > /home/pi/share/$(date +%F)_influx_backup.csv 2 | 3 | 4 | -------------------------------------------------------------------------------- /drivers/twi.h: -------------------------------------------------------------------------------- 1 | #ifndef __TWI_H__ 2 | #define __TWI_H__ 3 | 4 | 5 | #include "nrf_drv_twi.h" 6 | 7 | void twi_scan(); 8 | void twi_init(const nrf_drv_twi_t *p_twi); 9 | void twi_stop(); 10 | void twi_restart(); 11 | 12 | #endif /*__TWI_H__*/ 13 | -------------------------------------------------------------------------------- /drivers/clocks.h: -------------------------------------------------------------------------------- 1 | #ifndef __CLOCKS_H__ 2 | #define __CLOCKS_H__ 3 | 4 | typedef void (*app_rtc_handler_t)(void); 5 | 6 | void clocks_start(); 7 | void clocks_restart(); 8 | void clocks_stop(); 9 | 10 | void rtc_config(app_rtc_handler_t handler); 11 | 12 | #endif /*__CLOCKS_H__*/ -------------------------------------------------------------------------------- /raspi/leds_panel/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"leds_panel", 7 | "subscriptions":[], 8 | "publish" :true, 9 | "subscribe" :false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /drivers/app_ser.h: -------------------------------------------------------------------------------- 1 | #ifndef __APP_SER_H__ 2 | #define __APP_SER_H__ 3 | 4 | 5 | #include 6 | 7 | typedef void (*app_serial_handler_t)(const char*,uint8_t); 8 | 9 | void ser_init(app_serial_handler_t handler); 10 | void ser_send(char* message); 11 | 12 | #endif /*__APP_SER_H__*/ 13 | -------------------------------------------------------------------------------- /run_services.sh: -------------------------------------------------------------------------------- 1 | sudo cp raspi/rf_uart/mesh_controller.service /lib/systemd/system/ 2 | sudo chmod 644 /lib/systemd/system/mesh_controller.service 3 | sudo chmod +x raspi/rf_uart/mesh_controller.py 4 | sudo systemctl daemon-reload 5 | sudo systemctl enable mesh_controller.service 6 | sudo systemctl start mesh_controller.service 7 | 8 | -------------------------------------------------------------------------------- /applications/05_rotary_decoder/readme.md: -------------------------------------------------------------------------------- 1 | # Rotary encoder 2 | * https://www.amazon.de/gp/product/B015GYY7XU/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 3 | 4 | 5 | ## Sync 6 | send a sync message from node 107/0x68 7 | 8 | msg:0x804068 9 | msg:0x804168 10 | 11 | 12 | # PPI : Programmable Peripheral Interface 13 | ![ppi](ppi.svg) 14 | -------------------------------------------------------------------------------- /raspi/influx/backup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "Backing up the influx Databse" 3 | influxd backup /home/pi/share/$(date +%F)_influx_backup 4 | influxd backup -database meshNodes -since 2017-12-01T00:00:00Z /home/pi/share/$(date +%F)_influx_backup 5 | influxd backup -database meshNet -since 2017-12-01T00:00:00Z /home/pi/share/$(date +%F)_influx_backup 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "nRF5_SDK_15.0.0_prf"] 2 | path = nRF5_SDK_15.0.0_prf 3 | url = https://github.com/nRFMesh/nRF5_SDK_15.0.0_prf.git 4 | [submodule "nRF5_SDK_for_Thread_and_Zigbee_2.0.0_29775ac_min"] 5 | path = nRF5_SDK_for_Thread_and_Zigbee_2.0.0_29775ac_min 6 | url = https://github.com/nRFMesh/nRF5_SDK_for_Thread_and_Zigbee_2.0.0_29775ac_min 7 | -------------------------------------------------------------------------------- /raspi/esp32/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.12", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"rf_stm32", 7 | "subscriptions":[], 8 | "publish" :true, 9 | "subscribe" :false 10 | }, 11 | "log":{ 12 | "logfile":"/home/pi/share/esp32.log", 13 | "level":"Debug" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "sdk_common.h": "c", 4 | "nrf_drv_ppi.h": "c", 5 | "stdint.h": "c", 6 | "sdk_config.h": "c", 7 | "boards.h": "c", 8 | "pca10059.h": "c", 9 | "nrf.h": "c", 10 | "nrfx.h": "c", 11 | "nrf_ringbuf.h": "c" 12 | }, 13 | "C_Cpp.errorSquiggles": "Disabled" 14 | } -------------------------------------------------------------------------------- /raspi/rf_uart/mesh_controller.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=service using a dongle to listen to old gen uart custom RF devices and forward messages to mqtt 3 | After=multi-user.target 4 | 5 | [Service] 6 | Type=simple 7 | ExecStart=/usr/bin/python /home/pi/nRF52_Mesh/raspi/rf_uart/mesh_controller.py -c 2 -f l 8 | Restart=on-abort 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | -------------------------------------------------------------------------------- /drivers/compare.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMPARE_H__ 2 | #define __COMPARE_H__ 3 | 4 | 5 | #include 6 | 7 | typedef void (*app_compare_handler_t)(); 8 | 9 | typedef struct 10 | { 11 | uint32_t cycle, offset0, offset1; 12 | app_compare_handler_t call0, call1; 13 | }apptimer_config_t; 14 | 15 | void compare_init(apptimer_config_t config); 16 | 17 | #endif /*__COMPARE_H__*/ 18 | -------------------------------------------------------------------------------- /drivers/bldc.h: -------------------------------------------------------------------------------- 1 | #ifndef __APP_BLDC_H__ 2 | #define __APP_BLDC_H__ 3 | 4 | 5 | #include 6 | 7 | void bldc_init(); 8 | 9 | void bldc_set_target(int32_t absolute_steps); 10 | void bldc_set_speed(float v_rot_per_sec); 11 | void bldc_set_norm(float norm); 12 | void bldc_set_pole(int angle, float norm); 13 | void bldc_pwm_get(uint16_t *pwm1,uint16_t *pwm2,uint16_t *pwm3); 14 | 15 | #endif /*__APP_BLDC_H__*/ 16 | -------------------------------------------------------------------------------- /drivers/usb_print.h: -------------------------------------------------------------------------------- 1 | #ifndef __USB_PRINT_H__ 2 | #define __USB_PRINT_H__ 3 | 4 | 5 | #include 6 | #include 7 | 8 | typedef void (*usb_rx_handler_t)(const char*,uint8_t); 9 | 10 | void usb_print_init(usb_rx_handler_t handler); 11 | void usb_print_loop(); 12 | void usb_print(const void * p_buf,size_t length); 13 | void usb_printf(const char *format, ...); 14 | 15 | #endif /*__USB_PRINT_H__*/ 16 | -------------------------------------------------------------------------------- /raspi/influx/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"localhost", 4 | "port":1883, 5 | "keepalive":60, 6 | "root_topic":"zig" 7 | }, 8 | "influxdb":{ 9 | "host":"localhost", 10 | "port":8086, 11 | "db":"meshNodes", 12 | "mqtt_client_id":"py_influx" 13 | }, 14 | "log":{ 15 | "logfile":"/home/pi/share/influx_client.log", 16 | "level":"Debug" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /applications/uicr_map.json: -------------------------------------------------------------------------------- 1 | { 2 | "mesh_id" : "CUSTOMER_0", 3 | "channel" : "CUSTOMER_1", 4 | "sleep" : "CUSTOMER_2", 5 | "is_listening" : "CUSTOMER_3", 6 | "is_router" : "CUSTOMER_4", 7 | "is_rf_cmd" : "CUSTOMER_5", 8 | "is_rf2uart" : "CUSTOMER_6", 9 | "is_uart_cmd" : "CUSTOMER_7", 10 | "rtx_timeout" : "CUSTOMER_8", 11 | "rtx_max_timeout": "CUSTOMER_9", 12 | "rtx_count" : "CUSTOMER_10" 13 | } 14 | -------------------------------------------------------------------------------- /raspi/conbee/readme.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | This module is based on the Zigbee USB dongle [ConBee](https://www.dresden-elektronik.de/conbee/) 3 | * The [deCONZ](https://github.com/dresden-elektronik/deconz-rest-plugin) service has to be installed 4 | * It will provide a [REST API](http://dresden-elektronik.github.io/deconz-rest-doc/) interface 5 | 6 | This script will be requesting config info through REST API, then connect through websocket to get sensors events notifications 7 | 8 | -------------------------------------------------------------------------------- /raspi/influx/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.12", 4 | "port":1883, 5 | "keepalive":60, 6 | "root_topic":"zig" 7 | }, 8 | "influxdb":{ 9 | "host":"10.0.0.12", 10 | "port":8086, 11 | "db":"meshNodes", 12 | "mqtt_client_id":"py_influx" 13 | }, 14 | "log":{ 15 | "logfile":"D:\\Projects\\nRF52_Mesh\\raspi\\influx\\influx.log", 16 | "level":"Debug" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /drivers/timestamp.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIMESTAMP_TIMER_H__ 2 | #define __TIMESTAMP_TIMER_H__ 3 | 4 | 5 | #include 6 | 7 | void timestamp_init(); 8 | 9 | //timestamp_get() not efficient as triggers a capture event then ready the capture reg, no direct access to counter 10 | //actually the good thing is that it foreces the user to use TASKs to trigger teh capture and not do it by soft 11 | uint32_t timestamp_get(); 12 | void timestamp_reset(); 13 | 14 | #endif /*__TIMESTAMP_TIMER_H__*/ 15 | -------------------------------------------------------------------------------- /raspi/esp32/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.12", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"rf_stm32", 7 | "subscriptions":[ 8 | "status/#", 9 | "Nodes/98/temperature" 10 | ], 11 | "publish" :true, 12 | "subscribe" :true 13 | }, 14 | "log":{ 15 | "logfile":"D:\\Projects\\nRF52_Mesh\\raspi\\esp32\\esp32.log", 16 | "level":"Debug" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /drivers/strmap.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _STR_MAP_HPP_ 2 | #define _STR_MAP_HPP_ 3 | 4 | #include 5 | #include 6 | 7 | typedef std::map strmap_t; 8 | 9 | class strmap_c 10 | { 11 | public: 12 | strmap_c(const char*msg,uint8_t size); 13 | public: 14 | bool has(std::string key); 15 | std::string& operator [] (std::string key); 16 | public: 17 | std::string topic; 18 | strmap_t dict; 19 | }; 20 | 21 | 22 | #endif /*_STR_MAP_HPP_*/ 23 | -------------------------------------------------------------------------------- /raspi/conbee/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "conbee":{ 3 | "rest":"http://localhost/api/853212563154", 4 | "websocket":"ws://localhost:443" 5 | }, 6 | "mqtt":{ 7 | "host":"10.0.0.12", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"conbee_client", 11 | "subscriptions":[], 12 | "publish" :true, 13 | "subscribe" :false 14 | }, 15 | "log":{ 16 | "logfile":"/home/pi/share/conbee.log", 17 | "level":"Debug" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /raspi/conbee/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "conbee":{ 3 | "rest":"http://10.0.0.17/api/853212563154", 4 | "websocket":"ws://10.0.0.17:443" 5 | }, 6 | "mqtt":{ 7 | "host":"10.0.0.12", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"conbee_client", 11 | "subscriptions":[], 12 | "publish" :true, 13 | "subscribe" :false 14 | }, 15 | "log":{ 16 | "logfile":"./out_conbee.log", 17 | "level":"Debug" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /raspi/esp32/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"localhost", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"esp32_py", 7 | "subscriptions":[ 8 | "status/#", 9 | "mzig/bed weather", 10 | "mzig/bed heat button", 11 | "esp/bed heater/#" 12 | ], 13 | "publish" :true, 14 | "subscribe" :true 15 | }, 16 | "log":{ 17 | "logfile":"/home/pi/share/esp32.log", 18 | "level":"Info" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /raspi/raspi_run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #first time install : 4 | #pip install -r requirements.txt 5 | #python3 -m pip install -r requirements.txt 6 | 7 | #services 8 | mosquitto -c /etc/mosquitto/mosquitto.conf & 9 | sudo systemctl start grafana-server.service 10 | 11 | #scripts 12 | python rf_uart/mesh_controller.py -c 2 -f l & 13 | python wemo/wemo_client.py & 14 | python milight/milight_gateway.py & 15 | python ruler/ruler.py & 16 | #python3.6 conbee/conbee.py 17 | #this script would fail if influxdb is not yet available, it is therefore delayed 18 | sleep 15 && python influx/influx_client.py & 19 | 20 | -------------------------------------------------------------------------------- /drivers/usb_print.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __USB_PRINT_HPP__ 2 | #define __USB_PRINT_HPP__ 3 | 4 | 5 | #include 6 | 7 | typedef void (*usb_rx_handler_t)(const char*,uint8_t); 8 | 9 | void usb_print_init(usb_rx_handler_t handler); 10 | void usb_print_loop(); 11 | void usb_print(const void * p_buf,size_t length); 12 | void usb_printf(const char *format, ...); 13 | 14 | class usb_c 15 | { 16 | public: 17 | usb_c(usb_rx_handler_t handler); 18 | void send(const void * p_buf,size_t length); 19 | void printf(const char *format, ...); 20 | void loop(); 21 | 22 | }; 23 | 24 | 25 | #endif /*__USB_PRINT_HPP__*/ 26 | -------------------------------------------------------------------------------- /raspi/rf_uart/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"/dev/ttyUSB1", 4 | "baud":460800 5 | }, 6 | "mqtt":{ 7 | "host":"localhost", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"hci_client", 11 | "subscriptions":[ 12 | "Nodes/#", 13 | "cmd/request/#", 14 | "remote_cmd/request/#" 15 | ], 16 | "actions" :["dimmer","heat","ping"], 17 | "rf_2_mqtt" :true, 18 | "mqtt_2_rf" :true 19 | }, 20 | "log":{ 21 | "logfile":"/home/pi/share/rf_uart4.log", 22 | "level":"Info" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /raspi/rf_uart/config_rfserv.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"/dev/ttyUSB0", 4 | "baud":460800 5 | }, 6 | "mqtt":{ 7 | "host":"localhost", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"hci_client", 11 | "subscriptions":[ 12 | "Nodes/#", 13 | "cmd/request/#", 14 | "remote_cmd/request/#" 15 | ], 16 | "actions" :["dimmer","heat","ping"], 17 | "rf_2_mqtt" :true, 18 | "mqtt_2_rf" :true 19 | }, 20 | "log":{ 21 | "logfile":"/home/pi/share/rf_uart.log", 22 | "level":"Info" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /raspi/rf_uart/config_webserv.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"/dev/ttyUSB0", 4 | "baud":460800 5 | }, 6 | "mqtt":{ 7 | "host":"localhost", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"hci_client", 11 | "subscriptions":[ 12 | "Nodes/#", 13 | "cmd/request/#", 14 | "remote_cmd/request/#" 15 | ], 16 | "actions" :["dimmer","heat","ping"], 17 | "rf_2_mqtt" :true, 18 | "mqtt_2_rf" :true 19 | }, 20 | "log":{ 21 | "logfile":"/home/pi/share/rf_uart.log", 22 | "level":"Info" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /raspi/rf_stm32/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"/dev/ttyUSB0", 4 | "baud":115200 5 | }, 6 | "mqtt":{ 7 | "host":"localhost", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"rf_stm32", 11 | "subscriptions":[ ], 12 | "publish" :false, 13 | "subscribe" :false 14 | }, 15 | "log":{ 16 | "logfile":"/home/pi/share/stm32.log", 17 | "level":"Debug" 18 | }, 19 | "heat":{ 20 | "node_src" : 65, 21 | "node_dst" : 28 22 | }, 23 | "light":{ 24 | "node_src" : 65, 25 | "node_dst" : 25 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /raspi/rf_uart/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"COM18", 4 | "baud":460800 5 | }, 6 | "mqtt":{ 7 | "host":"10.0.0.12", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"hci_client", 11 | "subscriptions":[ 12 | "Nodes/#", 13 | "cmd/request/#", 14 | "remote_cmd/request/#" 15 | ], 16 | "actions" :["dimmer","heat","ping"], 17 | "rf_2_mqtt" :true, 18 | "mqtt_2_rf" :true 19 | }, 20 | "log":{ 21 | "logfile":"D:\\Dev\\nRF52_Mesh\\raspi\\rf_uart\\hci_client.log", 22 | "level":"Debug" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | "C:/Program Files (x86)/GNU Tools ARM Embedded/6 2017-q2-update/lib/gcc/arm-none-eabi/6.3.1/include" 8 | ], 9 | "defines": [ 10 | "_DEBUG", 11 | "UNICODE", 12 | "_UNICODE" 13 | ], 14 | "compilerPath": "/usr/bin/gcc", 15 | "cStandard": "c11", 16 | "cppStandard": "c++17", 17 | "intelliSenseMode": "clang-x64" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /drivers/mpu6050.h: -------------------------------------------------------------------------------- 1 | #ifndef MPU6050_APP_H 2 | #define MPU6050_APP_H 3 | 4 | #include 5 | 6 | #include "nrf_drv_twi.h" 7 | 8 | typedef void (*app_mpu_handler_t)(uint8_t); 9 | 10 | void mpu_dump_regs(); 11 | 12 | void mpu_init(const nrf_drv_twi_t *l_twi);//also wakes up 13 | 14 | void mpu_cycle();//cyclically wakeup from interrupt and update reagisters left ready to be read 15 | void mpu_motion_init(app_mpu_handler_t handler); 16 | 17 | void mpu_get_accell(float *x,float *y,float *z); 18 | void mpu_get_accell_data(uint8_t *data); 19 | void mpu_get_gyro_data(uint8_t *data); 20 | 21 | //experimental 22 | void mpu_wakeup(); 23 | void mpu_sleep(); 24 | 25 | #endif /*MPU6050_APP_H*/ -------------------------------------------------------------------------------- /drivers/max44009.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAX_44009_H__ 2 | #define __MAX_44009_H__ 3 | /** @file max44009.h 4 | * 5 | * @author Wassim FILALI 6 | * 7 | * @compiler IAR STM8 -> gcc 8 | * 9 | * 10 | * $Date: 29.10.2016 - creation out of refactoring 11 | * $Data: 06.05.2018 - port to nRF52 with nRF SDK 15 and gcc 12 | * $Revision: 2 13 | * 14 | */ 15 | 16 | #include 17 | 18 | #include "nrf_drv_twi.h" 19 | 20 | //read the light in mili-lux => x1000 21 | //resolution is 0.045 @ [0-11.5] ---> 737 @ [94K->188K] 22 | //0.05–0.3 Full moon on a clear night 23 | //10,000–25,000 Full daylight (not direct sun) 24 | //32,000–100,000 Direct sunlight 25 | uint32_t max44009_read_light(); 26 | 27 | void max44009_test(); 28 | 29 | #endif /*__MAX_44009_H__*/ 30 | -------------------------------------------------------------------------------- /drivers/usb_print.cpp: -------------------------------------------------------------------------------- 1 | extern "C" 2 | { 3 | #include "usb_print.h" 4 | } 5 | 6 | 7 | #include 8 | #include 9 | 10 | 11 | #include "usb_print.hpp" 12 | 13 | 14 | 15 | usb_c::usb_c(usb_rx_handler_t handler) 16 | { 17 | usb_print_init(handler); 18 | } 19 | 20 | void usb_c::send(const void * p_buf,size_t length) 21 | { 22 | usb_print(p_buf,length); 23 | } 24 | 25 | char usb_print_buffer_cpp[256]; 26 | 27 | void usb_c::printf(const char *format, ...) 28 | { 29 | va_list args; 30 | va_start (args, format); 31 | size_t length = vsnprintf(usb_print_buffer_cpp,256,format, args); 32 | va_end (args); 33 | 34 | usb_print(usb_print_buffer_cpp, length); 35 | } 36 | 37 | void usb_c::loop() 38 | { 39 | usb_print_loop(); 40 | } 41 | -------------------------------------------------------------------------------- /applications/uicr_user_defines.h: -------------------------------------------------------------------------------- 1 | #ifndef __USER_UICR_DEFINES__ 2 | #define __USER_UICR_DEFINES__ 3 | 4 | #define UICR_NODE_ID NRF_UICR->CUSTOMER[0] 5 | #define UICR_RF_CHANNEL NRF_UICR->CUSTOMER[1] 6 | #define UICR_SLEEP_SEC NRF_UICR->CUSTOMER[2] 7 | #define UICR_is_listening() (NRF_UICR->CUSTOMER[3] == 0xBABA) 8 | #define UICR_is_router() (NRF_UICR->CUSTOMER[4] == 0xBABA) 9 | #define UICR_is_rf_cmd() (NRF_UICR->CUSTOMER[5] == 0xBABA) 10 | #define UICR_is_rf2uart() (NRF_UICR->CUSTOMER[6] == 0xBABA) 11 | #define UICR_is_uart_cmd() (NRF_UICR->CUSTOMER[7] == 0xBABA) 12 | #define UICR_RTX_Timeout NRF_UICR->CUSTOMER[8] 13 | #define UICR_RTX_Max_Timeout NRF_UICR->CUSTOMER[9] 14 | #define UICR_RTX_Count NRF_UICR->CUSTOMER[10] 15 | 16 | 17 | #endif /*__USER_UICR_DEFINES__*/ -------------------------------------------------------------------------------- /raspi/wemo/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "devices":{ 3 | "Bed heating":{ 4 | "node":30 5 | }, 6 | "Dryer":{ 7 | "node":37 8 | }, 9 | "Washing machine":{ 10 | "node":40 11 | } 12 | }, 13 | "mqtt":{ 14 | "host":"localhost", 15 | "port":1883, 16 | "keepalive":60, 17 | "client_id":"py_wemo", 18 | "valuesTopics":{ 19 | "HeadTopic" :"Nodes/", 20 | "actions" :["power"] 21 | }, 22 | "subscriptions":[ 23 | "zig/tree" 24 | ], 25 | "publish" :true, 26 | "subscribe" :true 27 | }, 28 | "log":{ 29 | "logfile":"/home/pi/share/wemo.log", 30 | "level":"Info" 31 | }, 32 | "poll_sec":10 33 | } 34 | -------------------------------------------------------------------------------- /drivers/bldc.hpp: -------------------------------------------------------------------------------- 1 | #ifndef _APP_BLDC_HPP__ 2 | #define _APP_BLDC_HPP__ 3 | 4 | 5 | #include 6 | #include "nrf_pwm.h" 7 | 8 | class bldc_c 9 | { 10 | public: 11 | bldc_c(uint8_t pwm,uint8_t p1, uint8_t p2, uint8_t p3); 12 | void set_target(int32_t absolute_steps); 13 | void set_speed(float v_rot_per_sec); 14 | void set_norm(float norm); 15 | void set_pole(int angle); 16 | void get_pwm(uint16_t *pwm1,uint16_t *pwm2,uint16_t *pwm3); 17 | 18 | public: 19 | float norm; 20 | float rot_per_sec,steps_per_100_us; 21 | int nb_poles; 22 | float absolute_steps; 23 | float absolute_target; 24 | bool is_tracking; 25 | nrf_pwm_values_individual_t pwm_values; 26 | }; 27 | 28 | 29 | 30 | #endif /*_APP_BLDC_HPP__*/ 31 | -------------------------------------------------------------------------------- /raspi/heat/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"heat_client", 7 | "subscriptions":[ "zig/balcony door", 8 | "zig/balcony window right", 9 | "zig/balcony window left" 10 | ], 11 | "actions" :[], 12 | "publish" :true, 13 | "subscribe" :true 14 | }, 15 | "heatings":{ 16 | "living heat":{ 17 | "topic":"zig/living heat/set", 18 | "Apertures":[ 19 | "balcony door", 20 | "balcony window right", 21 | "balcony window left" 22 | ] 23 | } 24 | }, 25 | "log":{ 26 | "logfile":"/home/pi/share/heat.log", 27 | "level":"Debug" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /raspi/bathroom/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"heat_client", 7 | "subscriptions":[ "zig/balcony door", 8 | "zig/balcony window right", 9 | "zig/balcony window left" 10 | ], 11 | "actions" :[], 12 | "publish" :true, 13 | "subscribe" :true 14 | }, 15 | "heatings":{ 16 | "living heat":{ 17 | "topic":"zig/living heat/set", 18 | "Apertures":[ 19 | "balcony door", 20 | "balcony window right", 21 | "balcony window left" 22 | ] 23 | } 24 | }, 25 | "log":{ 26 | "logfile":"/home/pi/share/heat.log", 27 | "level":"Debug" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /raspi/bathroom/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"heat_client", 7 | "subscriptions":[ "zig/balcony door", 8 | "zig/balcony window right", 9 | "zig/balcony window left" 10 | ], 11 | "actions" :[], 12 | "publish" :true, 13 | "subscribe" :true 14 | }, 15 | "heatings":{ 16 | "living heat":{ 17 | "topic":"zig/living heat/set", 18 | "Apertures":[ 19 | "balcony door", 20 | "balcony window right", 21 | "balcony window left" 22 | ] 23 | } 24 | } 25 | , 26 | "log":{ 27 | "logfile":"./heat.log", 28 | "level":"Info" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /raspi/rf_stm32/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"/dev/ttyUSB0", 4 | "baud":115200 5 | }, 6 | "mqtt":{ 7 | "host":"localhost", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"rf_stm32", 11 | "subscriptions":[ 12 | "Bed Heater/#", 13 | "esp/bed heater/#", 14 | "Retro Light Upstairs/#", 15 | "zig/bed heater", 16 | "zig/retrolight1", 17 | "zig/retrolight2" 18 | ], 19 | "publish" :true, 20 | "subscribe" :true 21 | }, 22 | "log":{ 23 | "logfile":"/home/pi/share/stm32.log", 24 | "level":"Info" 25 | }, 26 | "heat":{ 27 | "node_src" : 65, 28 | "node_dst" : 28 29 | }, 30 | "light":{ 31 | "node_src" : 65, 32 | "node_dst" : 25 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /raspi/rf_uart/rf_uart.py: -------------------------------------------------------------------------------- 1 | import serial 2 | import binascii 3 | 4 | ser = serial.Serial() 5 | on_line_function = None 6 | 7 | def run(): 8 | res = None 9 | try: 10 | line = ser.readline().decode("utf-8") 11 | if(len(line)): 12 | line = line.replace('\r','') 13 | line = line.replace('\n','') 14 | on_line_function(line) 15 | except OSError as e: 16 | print("Handled exception: %s",str(e)) 17 | return res 18 | 19 | def send(data): 20 | ser.write(data.encode()) 21 | return 22 | 23 | def serial_start(config,serial_on_line): 24 | global on_line_function 25 | on_line_function = serial_on_line 26 | global ser 27 | ser = serial.Serial(config["serial"]["port"], 28 | config["serial"]["baud"], 29 | timeout=0.1) 30 | print("uart> %s"%(ser.name)) 31 | return ser 32 | -------------------------------------------------------------------------------- /raspi/rf_stm32/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "serial":{ 3 | "port":"COM4", 4 | "baud":115200 5 | }, 6 | "mqtt":{ 7 | "host":"10.0.0.42", 8 | "port":1883, 9 | "keepalive":60, 10 | "client_id":"rf_stm32", 11 | "subscriptions":[ 12 | "Bed Heater/#", 13 | "esp/bed heater/#", 14 | "Retro Light Upstairs/#", 15 | "zig/bed heater", 16 | "zig/retrolight1", 17 | "zig/retrolight2" 18 | ], 19 | "publish" :true, 20 | "subscribe" :true 21 | }, 22 | "log":{ 23 | "logfile":"D:\\Projects\\nRF52_Mesh\\raspi\\rf_stm32\\stm32.log", 24 | "level":"Debug" 25 | }, 26 | "heat":{ 27 | "node_src" : 56, 28 | "node_dst" : 28 29 | }, 30 | "light":{ 31 | "node_src" : 56, 32 | "node_dst" : 25 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /raspi/conbee/output.log: -------------------------------------------------------------------------------- 1 | pi@rfserv:~ $ mosquitto_sub -t 'zigbee/#' -v 2 | zigbee/lumi.sensor_cube.aqgl01/Aqara Cube 1 {"event": "wakeup"} 3 | zigbee/lumi.sensor_cube.aqgl01/Aqara Cube 1 {"event": "flip", "from": 4, "to": 6} 4 | zigbee/lumi.vibration.aq1/lumi.vibration.aq1 7 {"event": "shake"} 5 | zigbee/lumi.vibration.aq1/lumi.vibration.aq1 7 {"event": "tilt"} 6 | zigbee/lumi.vibration.aq1/lumi.vibration.aq1 7 {"event": "tilt"} 7 | zigbee/lumi.vibration.aq1/lumi.vibration.aq1 7 {"event": "drop"} 8 | zigbee/lumi.sensor_magnet.aq2/OpenClose 1 open 9 | zigbee/lumi.sensor_magnet.aq2/OpenClose 1 closed 10 | zigbee/lumi.sensor_cube.aqgl01/Aqara Cube 1 {"rotation": -5072} 11 | zigbee/lumi.sensor_cube.aqgl01/Aqara Cube 1 {"rotation": 6415} 12 | zigbee/lumi.sensor_cube.aqgl01/Aqara Cube 1 {"event": "drop"} 13 | zigbee/lumi.sensor_motion.aq2/MotionLight 1 presence 14 | zigbee/lumi.sensor_motion.aq2/MotionLight 1 presence 15 | -------------------------------------------------------------------------------- /raspi/rf_stm32/rf_uart.py: -------------------------------------------------------------------------------- 1 | import serial 2 | import binascii 3 | 4 | ser = serial.Serial() 5 | on_line_function = None 6 | 7 | def run(): 8 | res = None 9 | try: 10 | line = ser.readline().decode("utf-8", errors='ignore') 11 | if(len(line)): 12 | line = line.replace('\r','') 13 | line = line.replace('\n','') 14 | on_line_function(line) 15 | except OSError as e: 16 | print("Handled exception: %s",str(e)) 17 | #TODO handle UnicodeDecodeError error 18 | return res 19 | 20 | def send(data): 21 | ser.write(data.encode()) 22 | return 23 | 24 | def serial_start(config,serial_on_line): 25 | global on_line_function 26 | on_line_function = serial_on_line 27 | global ser 28 | ser = serial.Serial(config["serial"]["port"], 29 | config["serial"]["baud"], 30 | timeout=0.1) 31 | print("uart> %s"%(ser.name)) 32 | return ser 33 | -------------------------------------------------------------------------------- /drivers/strmap.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "strmap.hpp" 3 | 4 | #include 5 | 6 | std::string TakeParseTo(std::string &str,char sep) 7 | { 8 | std::string Parsed; 9 | size_t first = str.find_first_of(sep); 10 | if(first != std::string::npos) 11 | { 12 | Parsed = str.substr(0 , first); 13 | str = str.substr(first+1 ,str.length()); 14 | } 15 | else//not found, then take what's left 16 | { 17 | Parsed = str; 18 | str = ""; 19 | } 20 | return Parsed; 21 | } 22 | 23 | strmap_c::strmap_c(const char*msg,uint8_t size) 24 | { 25 | int max = 0; 26 | std::string str(msg,size); 27 | topic = TakeParseTo(str,'>'); 28 | while((!str.empty()) && (max < 20)) 29 | { 30 | std::string arg_name = TakeParseTo(str,':'); 31 | dict[arg_name] = TakeParseTo(str,';'); 32 | max++; 33 | } 34 | } 35 | 36 | 37 | bool strmap_c::has(std::string key) 38 | { 39 | return (dict.find(key) != dict.end()); 40 | } 41 | 42 | 43 | std::string& strmap_c::operator [] (std::string key) 44 | { 45 | return dict[key]; 46 | } -------------------------------------------------------------------------------- /raspi/ruler/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"localhost", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"py_ruler" 7 | }, 8 | "log":{ 9 | "logfile":"/home/pi/share/ruler.log", 10 | "level":"Info" 11 | }, 12 | "rules":{ 13 | "Bathroom_Window":{ 14 | "input":"jNodes/64/acceleration", 15 | "output":"Nodes/64/angle", 16 | "description":"captures the x3 accis of acceleration and turn it into an angle", 17 | "enable" : true 18 | }, 19 | "Bathroom_Heating":{ 20 | "input":"jNodes/45/acceleration", 21 | "output":"Nodes/45/angle", 22 | "description":"angle from the closed reference", 23 | "enable" : true 24 | }, 25 | "Kitchen_Move":{ 26 | "input":"zig/kitchen move", 27 | "output":"zig/printer light/set", 28 | "description":"low light for night hungers", 29 | "enable" : true 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /raspi/ruler/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"py_ruler_wd" 7 | }, 8 | "log":{ 9 | "logfile":"./log_ruler.log", 10 | "level":"Debug" 11 | }, 12 | "rules":{ 13 | "Bathroom_Window":{ 14 | "input":"jNodes/64/acceleration", 15 | "output":"Nodes/64/angle", 16 | "description":"captures the x3 accis of acceleration and turn it into an angle", 17 | "enable" : false 18 | }, 19 | "Bathroom_Heating":{ 20 | "input":"jNodes/45/acceleration", 21 | "output":"Nodes/45/angle", 22 | "description":"angle from the closed reference", 23 | "enable" : false 24 | }, 25 | "Kitchen_Move":{ 26 | "input":"zig/kitchen move", 27 | "output":"zig/printer light/set", 28 | "description":"low light for night hungers", 29 | "enable" : false 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /applications/04_uart_dongle/esb_ptx_prx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .log_const_data : 37 | { 38 | PROVIDE(__start_log_const_data = .); 39 | KEEP(*(SORT(.log_const_data*))) 40 | PROVIDE(__stop_log_const_data = .); 41 | } > FLASH 42 | .nrf_balloc : 43 | { 44 | PROVIDE(__start_nrf_balloc = .); 45 | KEEP(*(.nrf_balloc)) 46 | PROVIDE(__stop_nrf_balloc = .); 47 | } > FLASH 48 | 49 | } INSERT AFTER .text 50 | 51 | INCLUDE "nrf_common.ld" 52 | -------------------------------------------------------------------------------- /applications/06_bldc_52832/esb_ptx_prx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .log_const_data : 37 | { 38 | PROVIDE(__start_log_const_data = .); 39 | KEEP(*(SORT(.log_const_data*))) 40 | PROVIDE(__stop_log_const_data = .); 41 | } > FLASH 42 | .nrf_balloc : 43 | { 44 | PROVIDE(__start_nrf_balloc = .); 45 | KEEP(*(.nrf_balloc)) 46 | PROVIDE(__stop_nrf_balloc = .); 47 | } > FLASH 48 | 49 | } INSERT AFTER .text 50 | 51 | INCLUDE "nrf_common.ld" 52 | -------------------------------------------------------------------------------- /raspi/bathroom/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"bath_client", 7 | "subscriptions":[ "shellies/shellyswitch25-B8A4EE/input/0", 8 | "shellies/shellyswitch25-B8A4EE/relay/0", 9 | "shellies/shellyswitch25-B8A4EE/relay/1", 10 | "Nodes/82/humidity", 11 | "mzig/bathroom fan button" 12 | ], 13 | "publications" :[ "shellies/shellyswitch25-B8A4EE/relay/1/command" 14 | ], 15 | "publish" :true, 16 | "subscribe" :true 17 | }, 18 | "humidity":{ 19 | "start_fan":65, 20 | "stop_fan":60, 21 | "stop_fan_on_condition":62 22 | }, 23 | "input_to_fan_delay_min":5, 24 | "button_fan_short_min":10, 25 | "button_fan_long_min":30, 26 | "humidity_sensor_timeout_min":12, 27 | "log":{ 28 | "logfile":"/home/pi/share/bathroom.log", 29 | "level":"Info" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /applications/05_rotary_decoder/esb_ptx_prx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .log_const_data : 37 | { 38 | PROVIDE(__start_log_const_data = .); 39 | KEEP(*(SORT(.log_const_data*))) 40 | PROVIDE(__stop_log_const_data = .); 41 | } > FLASH 42 | .nrf_balloc : 43 | { 44 | PROVIDE(__start_nrf_balloc = .); 45 | KEEP(*(.nrf_balloc)) 46 | PROVIDE(__stop_nrf_balloc = .); 47 | } > FLASH 48 | 49 | } INSERT AFTER .text 50 | 51 | INCLUDE "nrf_common.ld" 52 | -------------------------------------------------------------------------------- /raspi/leds_panel/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | config = json.load(open(config_file)) 20 | else: 21 | config_file = dirname+'/'+"config.json" 22 | if(os.path.isfile(config_file)): 23 | config = json.load(open(config_file)) 24 | else: 25 | print("Fatal error 'config.json' not found") 26 | return config 27 | 28 | # -------------------- config -------------------- 29 | def get_local_nodes(nodes_file): 30 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 31 | return nodes 32 | 33 | -------------------------------------------------------------------------------- /tools/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import socket 4 | from collections import OrderedDict 5 | 6 | # -------------------- config -------------------- 7 | def get_local_json(): 8 | """fetches the config.json file in the local directory 9 | if config_hostname.json is found it is used over the default one 10 | """ 11 | config = None 12 | dirname = os.path.dirname(sys.argv[0]) 13 | if(len(dirname) == 0): 14 | dirname = "." 15 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 16 | if(os.path.isfile(config_file)): 17 | #print("loading: ",config_file) 18 | config = json.load(open(config_file)) 19 | else: 20 | config_file = dirname+'/'+"config.json" 21 | if(os.path.isfile(config_file)): 22 | #print("loading: %s",config_file) 23 | config = json.load(open(config_file)) 24 | else: 25 | print("Fatal error 'config.json' not found") 26 | return config 27 | 28 | # -------------------- config -------------------- 29 | def get_json(nodes_file): 30 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 31 | return nodes 32 | -------------------------------------------------------------------------------- /images/discourse.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Discourse_logo 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /applications/01_sensortag/esb_low_power_ptx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0000, LENGTH = 0x7F000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .pwr_mgmt_data : 37 | { 38 | PROVIDE(__start_pwr_mgmt_data = .); 39 | KEEP(*(SORT(.pwr_mgmt_data*))) 40 | PROVIDE(__stop_pwr_mgmt_data = .); 41 | } > FLASH 42 | .log_const_data : 43 | { 44 | PROVIDE(__start_log_const_data = .); 45 | KEEP(*(SORT(.log_const_data*))) 46 | PROVIDE(__stop_log_const_data = .); 47 | } > FLASH 48 | .nrf_balloc : 49 | { 50 | PROVIDE(__start_nrf_balloc = .); 51 | KEEP(*(.nrf_balloc)) 52 | PROVIDE(__stop_nrf_balloc = .); 53 | } > FLASH 54 | 55 | } INSERT AFTER .text 56 | 57 | INCLUDE "nrf_common.ld" 58 | -------------------------------------------------------------------------------- /applications/02_accell_tag/esb_low_power_ptx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0000, LENGTH = 0x7F000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .pwr_mgmt_data : 37 | { 38 | PROVIDE(__start_pwr_mgmt_data = .); 39 | KEEP(*(SORT(.pwr_mgmt_data*))) 40 | PROVIDE(__stop_pwr_mgmt_data = .); 41 | } > FLASH 42 | .log_const_data : 43 | { 44 | PROVIDE(__start_log_const_data = .); 45 | KEEP(*(SORT(.log_const_data*))) 46 | PROVIDE(__stop_log_const_data = .); 47 | } > FLASH 48 | .nrf_balloc : 49 | { 50 | PROVIDE(__start_nrf_balloc = .); 51 | KEEP(*(.nrf_balloc)) 52 | PROVIDE(__stop_nrf_balloc = .); 53 | } > FLASH 54 | 55 | } INSERT AFTER .text 56 | 57 | INCLUDE "nrf_common.ld" 58 | -------------------------------------------------------------------------------- /applications/03_buttons/esb_low_power_ptx_gcc_nrf52.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x0000, LENGTH = 0x7F000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 10 | } 11 | 12 | SECTIONS 13 | { 14 | } 15 | 16 | SECTIONS 17 | { 18 | . = ALIGN(4); 19 | .mem_section_dummy_ram : 20 | { 21 | } 22 | .log_dynamic_data : 23 | { 24 | PROVIDE(__start_log_dynamic_data = .); 25 | KEEP(*(SORT(.log_dynamic_data*))) 26 | PROVIDE(__stop_log_dynamic_data = .); 27 | } > RAM 28 | 29 | } INSERT AFTER .data; 30 | 31 | SECTIONS 32 | { 33 | .mem_section_dummy_rom : 34 | { 35 | } 36 | .pwr_mgmt_data : 37 | { 38 | PROVIDE(__start_pwr_mgmt_data = .); 39 | KEEP(*(SORT(.pwr_mgmt_data*))) 40 | PROVIDE(__stop_pwr_mgmt_data = .); 41 | } > FLASH 42 | .log_const_data : 43 | { 44 | PROVIDE(__start_log_const_data = .); 45 | KEEP(*(SORT(.log_const_data*))) 46 | PROVIDE(__stop_log_const_data = .); 47 | } > FLASH 48 | .nrf_balloc : 49 | { 50 | PROVIDE(__start_nrf_balloc = .); 51 | KEEP(*(.nrf_balloc)) 52 | PROVIDE(__stop_nrf_balloc = .); 53 | } > FLASH 54 | 55 | } INSERT AFTER .text 56 | 57 | INCLUDE "nrf_common.ld" 58 | -------------------------------------------------------------------------------- /raspi/milight/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "devices":{ 3 | "LivingRoom":{ 4 | "host":"10.0.0.8", 5 | "port":8899 6 | }, 7 | "Upstairs":{ 8 | "host":"10.0.0.6", 9 | "port":8899 10 | } 11 | }, 12 | "mapping":{ 13 | "31":{ 14 | "device" :"LivingRoom", 15 | "channel" :1 16 | }, 17 | "32":{ 18 | "device" :"LivingRoom", 19 | "channel" :2 20 | }, 21 | "33":{ 22 | "device" :"LivingRoom", 23 | "channel" :3 24 | }, 25 | "34":{ 26 | "device" :"LivingRoom", 27 | "channel" :4 28 | }, 29 | "35":{ 30 | "device" :"Upstairs", 31 | "channel" :1 32 | }, 33 | "36":{ 34 | "device" :"Upstairs", 35 | "channel" :2 36 | } 37 | }, 38 | "mqtt":{ 39 | "host":"localhost", 40 | "port":1883, 41 | "keepalive":60, 42 | "client_id":"python_milight", 43 | "subscribe":{ 44 | "Nodes" :["dimmer"] 45 | } 46 | }, 47 | "log":{ 48 | "logfile":"/home/pi/share/milight_gateway.log", 49 | "level":"Info" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /raspi/conbee/sensors_notifications.json: -------------------------------------------------------------------------------- 1 | [ 2 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 7000, "lastupdated": "2018-09-23T09:59:05"}, "t": "event"}, 3 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 1002, "lastupdated": "2018-09-23T09:59:05"}, "t": "event"}, 4 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 7000, "lastupdated": "2018-09-23T10:03:40"}, "t": "event"}, 5 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 6001, "lastupdated": "2018-09-23T10:03:41"}, "t": "event"}, 6 | {"e": "changed", "id": "7", "r": "sensors", "state": {"buttonevent": 1007, "lastupdated": "2018-09-23T10:03:42"}, "t": "event"}, 7 | {"action" : "flip 90"}, 8 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 7000, "lastupdated": "2018-09-23T10:23:34"}, "t": "event"}, 9 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 5006, "lastupdated": "2018-09-23T10:23:34"}, "t": "event"}, 10 | {"action" : "flip 90 back"}, 11 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 7000, "lastupdated": "2018-09-23T10:25:36"}, "t": "event"}, 12 | {"e": "changed", "id": "5", "r": "sensors", "state": {"buttonevent": 6005, "lastupdated": "2018-09-23T10:25:36"}, "t": "event"}, 13 | {"e": "changed", "id": "2", "r": "sensors", "t":"event","config":{"battery":95,"offset":0,"on":true,"reachable":true}} 14 | 15 | ] 16 | -------------------------------------------------------------------------------- /raspi/rf_uart/uart_failure.md: -------------------------------------------------------------------------------- 1 | # Exception occurred 2 | serial.serialutil.SerialException 3 | 4 | # Assumptions 5 | * /etc/rc.local started for no reason trying to add another instance on top of existing one 6 | 7 | # Resolution 8 | * Won't be investigated, right way is to use a service or other 9 | 10 | # Log 11 | 12 | Error log 13 | ``` 14 | [2020-06-21 04:36:47] Retrieving data from sensor "Flora1" ... 15 | rf > 110 kitchen tag : bme280 16 | rf > 76 bedroom tag : alive 17 | ('loading: %s', '/home/pi/nRF52_Mesh/raspi/rf_uart/config.json') 18 | uart> /dev/ttyUSB1 19 | Traceback (most recent call last): 20 | File "/home/pi/nRF52_Mesh/raspi/rf_uart/mesh_controller.py", line 213, in 21 | loop_forever() 22 | File "/home/pi/nRF52_Mesh/raspi/rf_uart/mesh_controller.py", line 142, in loop_forever 23 | mesh.run() 24 | File "/home/pi/nRF52_Mesh/raspi/rf_uart/mesh.py", line 220, in run 25 | ser.run() 26 | File "/home/pi/nRF52_Mesh/raspi/rf_uart/rf_uart.py", line 10, in run 27 | line = ser.readline().decode("utf-8") 28 | File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 490, in read 29 | 'device reports readiness to read but returned no data ' 30 | serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?) 31 | 1592707012: Socket error on client hci_client_mano, disconnecting. 32 | [2020-06-21 04:39:58] Retrying ... 33 | bed_light_button> taken 34 | [2020-06-21 04:43:10] Failed to retrieve data from Mi Flora sensor "Flora1" (C4:7C:8D:6A:B2:9D), success rate: 0% 35 | ``` 36 | -------------------------------------------------------------------------------- /applications/03_buttons/debug.jdebug.user: -------------------------------------------------------------------------------- 1 | OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=831, h=284, FilterBarShown=0, 2 | OpenWindow="Watched Data", DockArea=RIGHT, x=0, y=1, w=831, h=635, FilterBarShown=0, 3 | OpenWindow="Functions", DockArea=LEFT, x=0, y=1, w=1298, h=1106, FilterBarShown=1, 4 | OpenWindow="Memory1", DockArea=RIGHT, x=0, y=0, w=831, h=534, FilterBarShown=0, 5 | OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=1, w=831, h=635, FilterBarShown=0, ExecCountersShown=0 6 | OpenWindow="Registers", DockArea=LEFT, x=0, y=1, w=1298, h=1106, FilterBarShown=0, 7 | OpenWindow="Console", DockArea=RIGHT, x=0, y=2, w=831, h=284, FilterBarShown=0, 8 | OpenWindow="Breakpoints", DockArea=LEFT, x=0, y=0, w=1298, h=375, FilterBarShown=0, 9 | OpenToolbar="Debug", Floating=0, x=0, y=0 10 | TableHeader="Call Stack", SortCol="Function", SortOrder="ASCENDING", VisibleCols=["Function";"Stack Info";"Source"], ColWidths=[182;170;957] 11 | TableHeader="Watched Data", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location";"Size";"Refresh";"Type"], ColWidths=[133;134;134;74;105;729] 12 | TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[275;122;74;96;705] 13 | TableHeader="Registers", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Description"], ColWidths=[213;132;1437] 14 | TableHeader="Breakpoints", SortCol="State", SortOrder="ASCENDING", VisibleCols=["State";"Location";"Permitted Impl.";"Actual Impl.";"Context";"Task Filter";"Skip #";"Condition"], ColWidths=[85;242;176;146;770;128;96;122] 15 | -------------------------------------------------------------------------------- /applications/02_accell_tag/debug.jdebug.user: -------------------------------------------------------------------------------- 1 | OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=1, w=1309, h=617, FilterBarShown=0, ExecCountersShown=0 2 | OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=1309, h=343, FilterBarShown=0, 3 | OpenWindow="Watched Data", DockArea=RIGHT, x=0, y=1, w=1309, h=617, FilterBarShown=0, 4 | OpenWindow="Functions", DockArea=LEFT, x=0, y=1, w=662, h=1032, FilterBarShown=1, 5 | OpenWindow="Memory1", DockArea=RIGHT, x=0, y=0, w=1309, h=493, FilterBarShown=0, 6 | OpenWindow="Registers", DockArea=LEFT, x=0, y=1, w=662, h=1032, FilterBarShown=0, 7 | OpenWindow="Console", DockArea=RIGHT, x=0, y=2, w=1309, h=343, FilterBarShown=0, 8 | OpenWindow="Breakpoints", DockArea=LEFT, x=0, y=0, w=662, h=449, FilterBarShown=0, 9 | OpenToolbar="Debug", Floating=0, x=0, y=0 10 | TableHeader="Call Stack", SortCol="Function", SortOrder="ASCENDING", VisibleCols=["Function";"Stack Info";"Source"], ColWidths=[182;170;446] 11 | TableHeader="Watched Data", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location";"Size";"Refresh";"Type"], ColWidths=[133;230;134;74;105;633] 12 | TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[275;122;74;96;260] 13 | TableHeader="Registers", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Description"], ColWidths=[213;175;392] 14 | TableHeader="Breakpoints", SortCol="State", SortOrder="ASCENDING", VisibleCols=["State";"Location";"Permitted Impl.";"Actual Impl.";"Context";"Task Filter";"Skip #";"Condition"], ColWidths=[85;242;176;146;710;128;96;122] 15 | -------------------------------------------------------------------------------- /applications/08_usb_dongle/nRF52840_debug.jdebug.user: -------------------------------------------------------------------------------- 1 | OpenWindow="Functions", DockArea=LEFT, x=0, y=1, w=940, h=1209, FilterBarShown=1, 2 | OpenWindow="Console", DockArea=RIGHT, x=0, y=2, w=1303, h=407, FilterBarShown=0, 3 | OpenWindow="Disassembly", DockArea=RIGHT, x=0, y=1, w=1303, h=936, FilterBarShown=0, ExecCountersShown=0 4 | OpenWindow="Call Stack", DockArea=RIGHT, x=0, y=2, w=1303, h=407, FilterBarShown=0, 5 | OpenWindow="Watched Data", DockArea=RIGHT, x=0, y=1, w=1303, h=936, FilterBarShown=0, 6 | OpenWindow="Memory1", DockArea=RIGHT, x=0, y=0, w=1303, h=408, FilterBarShown=0, 7 | OpenWindow="Breakpoints", DockArea=LEFT, x=0, y=0, w=940, h=570, FilterBarShown=0, 8 | OpenWindow="Registers", DockArea=LEFT, x=0, y=1, w=940, h=1209, FilterBarShown=0, 9 | OpenToolbar="Debug", Floating=0, x=0, y=0 10 | TableHeader="Functions", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Address";"Size";"#Insts";"Source"], ColWidths=[275;122;74;96;347] 11 | TableHeader="Call Stack", SortCol="Function", SortOrder="ASCENDING", VisibleCols=["Function";"Stack Info";"Source"], ColWidths=[330;225;748] 12 | TableHeader="Watched Data", SortCol="Expression", SortOrder="ASCENDING", VisibleCols=["Expression";"Value";"Location";"Size";"Refresh";"Type"], ColWidths=[240;278;158;74;105;448] 13 | TableHeader="Breakpoints", SortCol="State", SortOrder="ASCENDING", VisibleCols=["State";"Location";"Permitted Impl.";"Actual Impl.";"Context";"Task Filter";"Skip #";"Condition"], ColWidths=[85;242;176;146;902;128;96;122] 14 | TableHeader="Registers", SortCol="Name", SortOrder="ASCENDING", VisibleCols=["Name";"Value";"Description"], ColWidths=[290;175;475] 15 | -------------------------------------------------------------------------------- /raspi/heat/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"heat_client", 7 | "subscriptions":[ "+/balcony door", 8 | "+/balcony window right", 9 | "+/balcony window left", 10 | "+/office window right", 11 | "+/office window left", 12 | "+/bedroom window", 13 | "+/kitchen window" 14 | ], 15 | "actions" :[], 16 | "publish" :true, 17 | "subscribe" :true 18 | }, 19 | "heatings":{ 20 | "living heat":{ 21 | "topic":"lzig/living heat/set", 22 | "Apertures":[ 23 | "balcony door", 24 | "balcony window right", 25 | "balcony window left" 26 | ] 27 | }, 28 | "office heat":{ 29 | "topic":"mzig/office heat/set", 30 | "Apertures":[ 31 | "office window right", 32 | "office window left" 33 | ] 34 | }, 35 | "bedroom heat":{ 36 | "topic":"lzig/bedroom heat/set", 37 | "Apertures":[ 38 | "bedroom window" 39 | ] 40 | }, 41 | "kitchen heat":{ 42 | "topic":"lzig/kitchen heat/set", 43 | "Apertures":[ 44 | "kitchen window" 45 | ] 46 | } 47 | }, 48 | "log":{ 49 | "logfile":"./heat.log", 50 | "level":"Debug" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /raspi/heat/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"heat_client", 7 | "subscriptions":[ "+/balcony door", 8 | "+/balcony window right", 9 | "+/balcony window left", 10 | "+/office window right", 11 | "+/office window left", 12 | "+/bedroom window", 13 | "+/kitchen window" 14 | ], 15 | "actions" :[], 16 | "publish" :true, 17 | "subscribe" :true 18 | }, 19 | "heatings":{ 20 | "living heat":{ 21 | "topic":"lzig/living heat/set", 22 | "Apertures":[ 23 | "balcony door", 24 | "balcony window right", 25 | "balcony window left" 26 | ] 27 | }, 28 | "office heat":{ 29 | "topic":"mzig/office heat/set", 30 | "Apertures":[ 31 | "office window right", 32 | "office window left" 33 | ] 34 | }, 35 | "bedroom heat":{ 36 | "topic":"lzig/bedroom heat/set", 37 | "Apertures":[ 38 | "bedroom window" 39 | ] 40 | }, 41 | "kitchen heat":{ 42 | "topic":"lzig/kitchen heat/set", 43 | "Apertures":[ 44 | "kitchen window" 45 | ] 46 | } 47 | }, 48 | "log":{ 49 | "logfile":"/home/pi/share/heat.log", 50 | "level":"Info" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /drivers/utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * @file utils.h 3 | * @author Wassim Filali 4 | * @date 01 June 2018 5 | * @brief File containing utilities for buffers and string manipulations 6 | * 7 | * 8 | */ 9 | 10 | #ifndef __UTILS_H__ 11 | #define __UTILS_H__ 12 | 13 | #include 14 | 15 | #define DEBUGPIN_RF 14 16 | #define DEBUGPIN_UART 29 17 | 18 | #define APP_DEBUG_PIN_SET(a) (NRF_GPIO->OUTSET = (1 << (a))) //!< Used internally to set debug pins. 19 | #define APP_DEBUG_PIN_CLR(a) (NRF_GPIO->OUTCLR = (1 << (a))) //!< Used internally to clear debug pins. 20 | 21 | 22 | uint16_t get_this_node_id(); 23 | 24 | int sprint_buf(char*str,const char*msg,uint8_t size); 25 | 26 | uint8_t strbegins (const char * s1, const char * s2); 27 | 28 | uint8_t text2bin(const char*text,uint8_t length,uint8_t*data,uint8_t*size); 29 | 30 | void blink_green(int time,int afteroff); 31 | void blink_red(int time,int afteroff); 32 | void blink_blue(int time,int afteroff); 33 | 34 | #if defined(BOARD_PCA10059) 35 | #define led2_green_on() bsp_board_led_on(0) 36 | #define led2_green_off() bsp_board_led_off(0) 37 | #define led1_red_on() bsp_board_led_on(1) 38 | #define led1_red_off() bsp_board_led_off(1) 39 | #define led1_green_on() bsp_board_led_on(2) 40 | #define led1_green_off() bsp_board_led_off(2) 41 | #define led1_blue_on() bsp_board_led_on(3) 42 | #define led1_blue_off() bsp_board_led_off(3) 43 | #else 44 | #define led2_green_on() 45 | #define led2_green_off() 46 | #define led1_red_on() 47 | #define led1_red_off() 48 | #define led1_green_on() 49 | #define led1_green_off() 50 | #define led1_blue_on() 51 | #define led1_blue_off() 52 | #endif 53 | 54 | #endif /*__UTILS_H__*/ -------------------------------------------------------------------------------- /drivers/timestamp.c: -------------------------------------------------------------------------------- 1 | 2 | #include "timestamp.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sdk_common.h" 8 | #include "sdk_config.h" 9 | 10 | #include "boards.h" 11 | 12 | #include "nrf_drv_timer.h" 13 | 14 | #include "nrf.h" 15 | 16 | #include "app_error.h" 17 | #include "app_util.h" 18 | 19 | #if(TIMESTAMP_ENABLED != 1) 20 | #error this file shall only be included if the BLDC is activated 21 | #endif 22 | 23 | #if (TIMER_ENABLED != 1) 24 | #error the timer instance must be enabled for bldc module 25 | #endif 26 | 27 | const nrf_drv_timer_t TIMER_TIMESTAMP = NRF_DRV_TIMER_INSTANCE(TIMESTAMP_TIMER_INSTANCE); 28 | 29 | void timer_dummy_handler(nrf_timer_event_t event_type, void * p_context) 30 | { 31 | } 32 | 33 | void timestamp_init() 34 | { 35 | ret_code_t err_code; 36 | 37 | nrf_drv_timer_config_t timer_cfg = { 38 | .frequency = (nrf_timer_frequency_t)NRF_TIMER_FREQ_1MHz, 39 | .mode = (nrf_timer_mode_t)NRF_TIMER_MODE_TIMER, 40 | .bit_width = (nrf_timer_bit_width_t)NRF_TIMER_BIT_WIDTH_32, 41 | .interrupt_priority = 7, 42 | .p_context = NULL 43 | }; 44 | err_code = nrf_drv_timer_init(&TIMER_TIMESTAMP, &timer_cfg, timer_dummy_handler); 45 | APP_ERROR_CHECK(err_code); 46 | 47 | // Enable timer 48 | nrf_drv_timer_enable(&TIMER_TIMESTAMP); 49 | } 50 | 51 | //timestamp_get() not efficient as triggers a capture event then ready the capture reg, no direct access to counter 52 | uint32_t timestamp_get() 53 | { 54 | return nrf_drv_timer_capture(&TIMER_TIMESTAMP, 0);//Capture channel 0 55 | } 56 | 57 | void timestamp_reset() 58 | { 59 | return nrf_drv_timer_clear(&TIMER_TIMESTAMP); 60 | } 61 | 62 | -------------------------------------------------------------------------------- /raspi/ruler/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"localhost", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"py_ruler" 7 | }, 8 | "log":{ 9 | "logfile":"/home/pi/share/ruler.log", 10 | "level":"Info" 11 | }, 12 | "rules":{ 13 | "Bathroom_Fan":{ 14 | "input":"shellies/shellyswitch25-B8A4EE/input/0", 15 | "output":"shellies/shellyswitch25-B8A4EE/relay/0/command", 16 | "description":"delay the light to control the bathroom fan", 17 | "enable" : false 18 | }, 19 | "Bathroom_Heating":{ 20 | "input":"jNodes/45/acceleration", 21 | "output":"Nodes/45/angle", 22 | "description":"angle from the closed reference", 23 | "enable" : false 24 | }, 25 | "Kitchen_Move":{ 26 | "input":"zig/kitchen move", 27 | "output":"zig/printer light/set", 28 | "description":"low light for night hungers", 29 | "enable" : false 30 | }, 31 | "Upstairs_Heat":{ 32 | "input":"zig/desk motion", 33 | "output":"heating/upstairs", 34 | "description":"from heat handle angle to the heating value", 35 | "enable" : false 36 | }, 37 | "Bedroom_Heat_1":{ 38 | "input":"zig/motion 1_6", 39 | "output":"heating/bedroom_1", 40 | "description":"from heat handle angle to the heating value", 41 | "enable" : false 42 | }, 43 | "Bathroom_Window":{ 44 | "input":"jNodes/64/acceleration", 45 | "output":"Nodes/64/angle", 46 | "description":"captures the x3 accis of acceleration and turn it into an angle", 47 | "enable" : false 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /raspi/home_status/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"home_status_client", 7 | "subscriptions":[ "+/balcony door", 8 | "+/balcony window right", 9 | "+/balcony window left", 10 | "+/office window right", 11 | "+/office window left", 12 | "+/bedroom window", 13 | "+/kitchen window", 14 | "lzig/living heat", 15 | "mzig/office heat", 16 | "lzig/bedroom heat", 17 | "lzig/bathroom heat", 18 | "lzig/kitchen heat" 19 | ], 20 | "actions" :[], 21 | "publish" :true, 22 | "subscribe" :true 23 | }, 24 | "heaters":[ 25 | "living heat", 26 | "office heat", 27 | "bedroom heat", 28 | "kitchen heat", 29 | "bathroom heat" 30 | ], 31 | "apertures":[ 32 | "balcony door", 33 | "balcony window right", 34 | "balcony window left", 35 | "office window right", 36 | "office window left", 37 | "bedroom window", 38 | "kitchen window" 39 | ], 40 | "status":{ 41 | "red":{ 42 | "on":"http://10.0.0.48/settings/?led_power_disable=false", 43 | "off":"http://10.0.0.48/settings/?led_power_disable=true" 44 | }, 45 | "blue":{ 46 | "on":"http://10.0.0.48/settings/?led_status_disable=false", 47 | "off":"http://10.0.0.48/settings/?led_status_disable=true" 48 | } 49 | }, 50 | "log":{ 51 | "logfile":"/home/pi/share/home_status.log", 52 | "level":"Info" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /raspi/home_status/config_WassDell.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"home_status", 7 | "subscriptions":[ "+/balcony door", 8 | "+/balcony window right", 9 | "+/balcony window left", 10 | "+/office window right", 11 | "+/office window left", 12 | "+/bedroom window", 13 | "+/kitchen window", 14 | "lzig/living heat", 15 | "mzig/office heat", 16 | "lzig/bedroom heat", 17 | "lzig/bathroom heat", 18 | "lzig/kitchen heat" 19 | ], 20 | "actions" :[], 21 | "publish" :true, 22 | "subscribe" :true 23 | }, 24 | "heaters":[ 25 | "living heat", 26 | "office heat", 27 | "bedroom heat", 28 | "kitchen heat", 29 | "bathroom heat" 30 | ], 31 | "apertures":[ 32 | "balcony door", 33 | "balcony window right", 34 | "balcony window left", 35 | "office window right", 36 | "office window left", 37 | "bedroom window", 38 | "kitchen window" 39 | ], 40 | "status":{ 41 | "red":{ 42 | "on":"http://10.0.0.48/settings/?led_power_disable=false", 43 | "off":"http://10.0.0.48/settings/?led_power_disable=true" 44 | }, 45 | "blue":{ 46 | "on":"http://10.0.0.48/settings/?led_status_disable=false", 47 | "off":"http://10.0.0.48/settings/?led_status_disable=true" 48 | } 49 | }, 50 | "log":{ 51 | "logfile":"./home_status.log", 52 | "level":"Debug" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /raspi/home_status/config_mano.json: -------------------------------------------------------------------------------- 1 | { 2 | "mqtt":{ 3 | "host":"10.0.0.42", 4 | "port":1883, 5 | "keepalive":60, 6 | "client_id":"home_status_client", 7 | "subscriptions":[ "+/balcony door", 8 | "+/balcony window right", 9 | "+/balcony window left", 10 | "+/office window right", 11 | "+/office window left", 12 | "+/bedroom window", 13 | "+/kitchen window", 14 | "lzig/living heat", 15 | "mzig/office heat", 16 | "lzig/bedroom heat", 17 | "lzig/bathroom heat", 18 | "lzig/kitchen heat" 19 | ], 20 | "actions" :[], 21 | "publish" :true, 22 | "subscribe" :true 23 | }, 24 | "heaters":[ 25 | "living heat", 26 | "office heat", 27 | "bedroom heat", 28 | "kitchen heat", 29 | "bathroom heat" 30 | ], 31 | "apertures":[ 32 | "balcony door", 33 | "balcony window right", 34 | "balcony window left", 35 | "office window right", 36 | "office window left", 37 | "bedroom window", 38 | "kitchen window" 39 | ], 40 | "status":{ 41 | "red":{ 42 | "on":"http://192.168.0.109/settings/?led_power_disable=false", 43 | "off":"http://192.168.0.109/settings/?led_power_disable=true" 44 | }, 45 | "blue":{ 46 | "on":"http://192.168.0.109/settings/?led_status_disable=false", 47 | "off":"http://192.168.0.109/settings/?led_status_disable=true" 48 | } 49 | }, 50 | "log":{ 51 | "logfile":"/home/pi/share/home_status.log", 52 | "level":"Info" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /drivers/compare.c: -------------------------------------------------------------------------------- 1 | 2 | #include "compare.h" 3 | 4 | #include 5 | #include 6 | 7 | #include "sdk_common.h" 8 | #include "sdk_config.h" 9 | 10 | #include "boards.h" 11 | 12 | #include "nrf_drv_timer.h" 13 | 14 | #include "nrf.h" 15 | 16 | #include "app_error.h" 17 | #include "app_util.h" 18 | 19 | #if (TIMER_ENABLED != 1) 20 | #error the timer instance must be enabled for bldc module 21 | #endif 22 | 23 | const nrf_drv_timer_t TIMER_COMPARE = NRF_DRV_TIMER_INSTANCE(COMPARE_TIMER_INSTANCE); 24 | 25 | apptimer_config_t m_config; 26 | 27 | void timer_compare_handler(nrf_timer_event_t event_type, void * p_context) 28 | { 29 | switch (event_type) 30 | { 31 | case NRF_TIMER_EVENT_COMPARE0: 32 | { 33 | m_config.call0(); 34 | } 35 | break; 36 | case NRF_TIMER_EVENT_COMPARE1: 37 | { 38 | m_config.call1(); 39 | } 40 | break; 41 | default: 42 | //Do nothing. 43 | break; 44 | } 45 | } 46 | 47 | void compare_init(apptimer_config_t config) 48 | { 49 | ret_code_t err_code; 50 | 51 | nrf_drv_timer_config_t timer_cfg = { 52 | .frequency = (nrf_timer_frequency_t)NRF_TIMER_FREQ_1MHz, 53 | .mode = (nrf_timer_mode_t)NRF_TIMER_MODE_TIMER, 54 | .bit_width = (nrf_timer_bit_width_t)NRF_TIMER_BIT_WIDTH_32, 55 | .interrupt_priority = 7, 56 | .p_context = NULL 57 | }; 58 | err_code = nrf_drv_timer_init(&TIMER_COMPARE, &timer_cfg, timer_compare_handler); 59 | APP_ERROR_CHECK(err_code); 60 | 61 | m_config = config; 62 | nrf_drv_timer_compare(&TIMER_COMPARE,0,m_config.offset0,true); 63 | nrf_drv_timer_compare(&TIMER_COMPARE,1,m_config.offset1,true); 64 | nrf_drv_timer_compare(&TIMER_COMPARE,5,m_config.cycle,true); 65 | 66 | // Enable timer 67 | nrf_drv_timer_enable(&TIMER_COMPARE); 68 | } 69 | -------------------------------------------------------------------------------- /raspi/leds_panel/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | except socket.error: 42 | sleep(10) 43 | return 44 | 45 | global conf 46 | conf = config 47 | clientMQTT = None 48 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 49 | config["mqtt"]["enable"] = True 50 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 51 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 52 | clientMQTT.on_connect = None 53 | clientMQTT.on_message = None 54 | mqtt_connect_retries(clientMQTT) 55 | if(start_looping): 56 | #the loop will be called in the run main loop() 57 | clientMQTT.loop_start() 58 | else: 59 | config["mqtt"]["enable"] = False 60 | return clientMQTT 61 | -------------------------------------------------------------------------------- /raspi/rf_uart/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["mqtt_2_rf"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["rf_2_mqtt"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["rf_2_mqtt"] or config["mqtt"]["mqtt_2_rf"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | #the loop will be called in the run main loop() 58 | #clientMQTT.loop_start() 59 | else: 60 | config["mqtt"]["enable"] = False 61 | return clientMQTT 62 | -------------------------------------------------------------------------------- /raspi/esp32/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/esp32/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop will be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/heat/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop could be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/ruler/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/wemo/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/wemo/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop will be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/bathroom/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop could be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/conbee/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop will be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/influx/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/influx/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop could be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/milight/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/rf_stm32/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/rf_stm32/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop will be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/rf_uart/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | # -------------------- config -------------------- 9 | def get_local_json(): 10 | """fetches the config.json file in the local directory 11 | if config_hostname.json is found it is used over the default one 12 | """ 13 | config = None 14 | dirname = os.path.dirname(sys.argv[0]) 15 | if(len(dirname) == 0): 16 | dirname = "." 17 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 18 | if(os.path.isfile(config_file)): 19 | print("loading: ",config_file) 20 | config = json.load(open(config_file)) 21 | else: 22 | config_file = dirname+'/'+"config.json" 23 | if(os.path.isfile(config_file)): 24 | print("loading: %s",config_file) 25 | config = json.load(open(config_file)) 26 | else: 27 | print("Fatal error 'config.json' not found") 28 | return config 29 | 30 | # -------------------- config -------------------- 31 | def get_local_nodes(nodes_file): 32 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 33 | return nodes 34 | 35 | def configure_log(logger_name): 36 | global_config = get_local_json() 37 | config = global_config["log"] 38 | log_level_map = { 39 | "Debug" :10, 40 | "Info" :20, 41 | "Warning" :30, 42 | "Error" :40, 43 | "Critical" :50 44 | } 45 | #if(os.path.isfile(config["logfile"])): 46 | for handler in log.root.handlers[:]: 47 | log.root.removeHandler(handler) 48 | log.basicConfig( filename=config["logfile"], 49 | level=log_level_map[config["level"]], 50 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 51 | datefmt='%d %H:%M:%S' 52 | ) 53 | log.getLogger('').addHandler(log.StreamHandler()) 54 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 55 | #else: 56 | # print("Log file not available : %s"%(config["logfile"])) 57 | return global_config 58 | -------------------------------------------------------------------------------- /raspi/home_status/mqtt.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import socket 8 | 9 | conf = {} 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | global conf 14 | log.info("mqtt> connected with result code "+str(rc)) 15 | if(conf["mqtt"]["subscribe"]): 16 | for sub in userdata["mqtt"]["subscriptions"]: 17 | log.info("mqtt> Subscription to %s",sub) 18 | lclient.subscribe(sub) 19 | else: 20 | log.info("mqtt> Subscriptions not enabled") 21 | if(conf["mqtt"]["publish"]): 22 | log.info("mqtt> Publishing enabled") 23 | else: 24 | log.info("mqtt> Publishing not enabled") 25 | 26 | 27 | 28 | def ruler_loop_forever(): 29 | while(True): 30 | sleep(10) 31 | return 32 | 33 | 34 | def mqtt_start(config,mqtt_on_message,start_looping): 35 | def mqtt_connect_retries(client): 36 | connected = False 37 | while(not connected): 38 | try: 39 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 40 | connected = True 41 | log.info( "mqtt> connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 42 | except socket.error: 43 | log.error("socket.error will try a reconnection in 10 s") 44 | sleep(10) 45 | return 46 | 47 | global conf 48 | conf = config 49 | clientMQTT = None 50 | if(config["mqtt"]["publish"] or config["mqtt"]["subscribe"]): 51 | config["mqtt"]["enable"] = True 52 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 53 | clientMQTT = mqtt.Client(client_id=cid,userdata=config) 54 | clientMQTT.on_connect = on_connect 55 | clientMQTT.on_message = mqtt_on_message 56 | mqtt_connect_retries(clientMQTT) 57 | if(start_looping): 58 | #the loop could be called in the run main loop() 59 | clientMQTT.loop_start() 60 | else: 61 | config["mqtt"]["enable"] = False 62 | return clientMQTT 63 | -------------------------------------------------------------------------------- /raspi/hue/hue_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Philips hue", 3 | "zigbeechannel": 15, 4 | "bridgeid": "001788FFFE6BCD30", 5 | "mac": "00:17:88:6b:cd:30", 6 | "dhcp": true, 7 | "ipaddress": "10.0.0.38", 8 | "netmask": "255.255.255.0", 9 | "gateway": "10.0.0.1", 10 | "proxyaddress": "none", 11 | "proxyport": 0, 12 | "UTC": "2018-09-02T11:00:12", 13 | "localtime": "2018-09-02T13:00:12", 14 | "timezone": "Europe/Berlin", 15 | "modelid": "BSB002", 16 | "datastoreversion": "71", 17 | "swversion": "1806051111", 18 | "apiversion": "1.26.0", 19 | "swupdate": { 20 | "updatestate": 2, 21 | "checkforupdate": false, 22 | "devicetypes": { 23 | "bridge": false, 24 | "lights": [ 25 | "1" 26 | ], 27 | "sensors": [] 28 | }, 29 | "url": "", 30 | "text": "ZGB_100B_010F - 6.0", 31 | "notify": true 32 | }, 33 | "swupdate2": { 34 | "checkforupdate": false, 35 | "lastchange": "2018-09-01T19:52:32", 36 | "bridge": { 37 | "state": "noupdates", 38 | "lastinstall": "2018-09-01T18:03:57" 39 | }, 40 | "state": "anyreadytoinstall", 41 | "autoinstall": { 42 | "updatetime": "T14:00:00", 43 | "on": false 44 | } 45 | }, 46 | "linkbutton": false, 47 | "portalservices": false, 48 | "portalconnection": "connected", 49 | "portalstate": { 50 | "signedon": true, 51 | "incoming": false, 52 | "outgoing": true, 53 | "communication": "disconnected" 54 | }, 55 | "internetservices": { 56 | "internet": "connected", 57 | "remoteaccess": "disconnected", 58 | "time": "connected", 59 | "swupdate": "connected" 60 | }, 61 | "factorynew": false, 62 | "replacesbridgeid": null, 63 | "backup": { 64 | "status": "idle", 65 | "errorcode": 0 66 | }, 67 | "starterkitid": "", 68 | "whitelist": { 69 | "SQkJqlYFrLNoYighcL6od7FekjGqK3DP-XurmLmI": { 70 | "last use date": "2018-09-01T20:09:55", 71 | "create date": "2018-09-01T18:01:13", 72 | "name": "Hue 3#Samsung SM-G900F" 73 | }, 74 | "AB7nAWdmY3r9dnBtKduoF4pSru4BGSnur5khotYg": { 75 | "last use date": "2018-09-01T18:48:55", 76 | "create date": "2018-09-01T18:37:29", 77 | "name": "python_hue" 78 | }, 79 | "YXb1he50MGnuM6Jb9ZHpaCMTvuUKIUrdjLw56FOm": { 80 | "last use date": "2018-09-02T11:00:12", 81 | "create date": "2018-09-01T18:39:58", 82 | "name": "python_hue" 83 | } 84 | } 85 | } -------------------------------------------------------------------------------- /drivers/twi.c: -------------------------------------------------------------------------------- 1 | 2 | #include "twi.h" 3 | 4 | #include "sdk_common.h" 5 | 6 | #include "nrf_log.h" 7 | #include "nrf_log_ctrl.h" 8 | #include "nrf_log_default_backends.h" 9 | 10 | #include "boards.h" 11 | 12 | 13 | // --------------------- inputs from sdk_config --------------------- 14 | // ---> TWI_DEFAULT_CONFIG_FREQUENCY 15 | 16 | 17 | //------------------------------------------------------------------- 18 | 19 | /* TWI instance. */ 20 | static const nrf_drv_twi_t *p_twi = NULL; 21 | 22 | 23 | /* Number of possible TWI addresses. */ 24 | #define TWI_ADDRESSES 127 25 | 26 | 27 | //TODO optimisation 28 | // * 400K did not work on 10 cm test wire lines => using 100K, to check again with PCB 29 | void twi_init(const nrf_drv_twi_t *l_twi) 30 | { 31 | ret_code_t err_code; 32 | 33 | p_twi = l_twi; 34 | 35 | const nrf_drv_twi_config_t twi_config = { 36 | .scl = I2C_SCL, 37 | .sda = I2C_SDA, 38 | .frequency = TWI_DEFAULT_CONFIG_FREQUENCY, 39 | .interrupt_priority = APP_IRQ_PRIORITY_HIGH, 40 | .clear_bus_init = false 41 | }; 42 | 43 | err_code = nrf_drv_twi_init(p_twi, &twi_config, NULL, NULL); 44 | APP_ERROR_CHECK(err_code); 45 | 46 | nrf_drv_twi_enable(p_twi); 47 | } 48 | 49 | void twi_stop() 50 | { 51 | nrf_drv_twi_disable(p_twi); 52 | nrf_drv_twi_uninit(p_twi); 53 | //nRF52832 Errata [89] TWI: Static 400 uA current while using GPIOTE 54 | *(volatile uint32_t *)0x40003FFC = 0; 55 | *(volatile uint32_t *)0x40003FFC; 56 | *(volatile uint32_t *)0x40003FFC = 1; 57 | } 58 | 59 | void twi_restart() 60 | { 61 | //due to workaround Errata [89] Reconfiguration of TWI is required before next usage 62 | twi_init(p_twi); 63 | } 64 | 65 | 66 | //found BME280 @ 0x76 67 | //found MX44009 @ 0x4A 68 | void twi_scan() 69 | { 70 | ret_code_t err_code; 71 | uint8_t address; 72 | uint8_t sample_data; 73 | bool detected_device = false; 74 | 75 | for (address = 1; address <= TWI_ADDRESSES; address++) 76 | { 77 | err_code = nrf_drv_twi_rx(p_twi, address, &sample_data, sizeof(sample_data)); 78 | if (err_code == NRF_SUCCESS) 79 | { 80 | detected_device = true; 81 | NRF_LOG_INFO("TWI device detected at address 0x%x.", address); 82 | } 83 | NRF_LOG_FLUSH(); 84 | } 85 | 86 | if (!detected_device) 87 | { 88 | NRF_LOG_INFO("No device was found."); 89 | NRF_LOG_FLUSH(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /drivers/clocks.c: -------------------------------------------------------------------------------- 1 | 2 | #include "clocks.h" 3 | 4 | #include "sdk_common.h" 5 | #include "boards.h" 6 | 7 | //attempt to move to nrfx but nrf_drv_clock_init() do not have application examples,... 8 | #include "nrf_drv_clock.h" 9 | #include "nrf_drv_rtc.h" 10 | 11 | #define NRF_LOG_MODULE_NAME clocks 12 | 13 | #if (CLOCKS_CONFIG_LOG_ENABLED == 1) 14 | #define NRF_LOG_LEVEL CLOCKS_CONFIG_LOG_LEVEL 15 | #else //CLOCKS_CONFIG_LOG_ENABLED 16 | #define NRF_LOG_LEVEL 0 17 | #endif //CLOCKS_CONFIG_LOG_ENABLED 18 | 19 | #include "nrf_log.h" 20 | NRF_LOG_MODULE_REGISTER(); 21 | 22 | #include "uicr_user_defines.h" 23 | 24 | 25 | const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of nrf_drv_rtc for RTC0. */ 26 | 27 | static app_rtc_handler_t m_app_rtc_handler; 28 | 29 | void clocks_start( void ) 30 | { 31 | ret_code_t err_code; 32 | 33 | err_code = nrf_drv_clock_init(); 34 | APP_ERROR_CHECK(err_code); 35 | 36 | nrf_drv_clock_hfclk_request(NULL); 37 | while(!nrf_drv_clock_hfclk_is_running()); 38 | 39 | } 40 | 41 | void clocks_restart( void ) 42 | { 43 | nrf_drv_clock_hfclk_request(NULL); 44 | while(!nrf_drv_clock_hfclk_is_running()); 45 | } 46 | 47 | void clocks_stop( void ) 48 | { 49 | nrf_drv_clock_hfclk_release(); 50 | } 51 | 52 | void rtc_handler(nrf_drv_rtc_int_type_t int_type) 53 | { 54 | if (int_type == NRF_DRV_RTC_INT_COMPARE0) 55 | { 56 | nrf_drv_rtc_counter_clear(&rtc); 57 | nrf_drv_rtc_int_enable(&rtc, NRF_RTC_INT_COMPARE0_MASK); 58 | NRF_LOG_DEBUG("rtc_handler(COMPARE)"); 59 | 60 | static uint8_t send = 1; 61 | NRF_LOG_INFO("rtc_handler() %d",send); 62 | send++; 63 | 64 | m_app_rtc_handler(); 65 | 66 | } 67 | } 68 | 69 | void rtc_config(app_rtc_handler_t handler) 70 | { 71 | uint32_t err_code; 72 | 73 | m_app_rtc_handler = handler; 74 | 75 | nrf_drv_clock_lfclk_request(NULL); 76 | 77 | //Initialize RTC instance 78 | nrf_drv_rtc_config_t config = NRF_DRV_RTC_DEFAULT_CONFIG; 79 | config.prescaler = 4095; 80 | err_code = nrf_drv_rtc_init(&rtc, &config, rtc_handler); 81 | APP_ERROR_CHECK(err_code); 82 | 83 | //Enable tick event & interrupt 84 | //nrf_drv_rtc_tick_enable(&rtc,true); 85 | 86 | //Set compare channel to trigger interrupt after COMPARE_COUNTERTIME seconds 87 | err_code = nrf_drv_rtc_cc_set(&rtc,0,UICR_SLEEP_SEC * 8,true); 88 | APP_ERROR_CHECK(err_code); 89 | 90 | //Power on RTC instance 91 | nrf_drv_rtc_enable(&rtc); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /raspi/heat/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | from platform import system as system_name # Returns the system/OS name 9 | from subprocess import call as system_call # Execute a shell command 10 | 11 | def ping(host): 12 | """ 13 | Returns True if host (str) responds to a ping request. 14 | Remember that a host may not respond to a ping (ICMP) request even if the host name is valid. 15 | """ 16 | 17 | # Ping command count option as function of OS 18 | param = '-n' if system_name().lower()=='windows' else '-c' 19 | 20 | # Building the command. Ex: "ping -c 1 google.com" 21 | command = ['ping', param, '1', host] 22 | 23 | # Pinging 24 | return system_call(command) == 0 25 | 26 | # -------------------- config -------------------- 27 | def get_local_json(): 28 | """fetches the config.json file in the local directory 29 | if config_hostname.json is found it is used over the default one 30 | """ 31 | config = None 32 | dirname = os.path.dirname(sys.argv[0]) 33 | if(len(dirname) == 0): 34 | dirname = "." 35 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 36 | if(os.path.isfile(config_file)): 37 | print("loading: ",config_file) 38 | config = json.load(open(config_file)) 39 | else: 40 | config_file = dirname+'/'+"config.json" 41 | if(os.path.isfile(config_file)): 42 | print("loading: %s",config_file) 43 | config = json.load(open(config_file)) 44 | else: 45 | print("Fatal error 'config.json' not found") 46 | return config 47 | 48 | # -------------------- config -------------------- 49 | def get_local_nodes(nodes_file): 50 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 51 | return nodes 52 | 53 | def configure_log(logger_name): 54 | global_config = get_local_json() 55 | config = global_config["log"] 56 | log_level_map = { 57 | "Debug" :10, 58 | "Info" :20, 59 | "Warning" :30, 60 | "Error" :40, 61 | "Critical" :50 62 | } 63 | #if(os.path.isfile(config["logfile"])): 64 | for handler in log.root.handlers[:]: 65 | log.root.removeHandler(handler) 66 | log.basicConfig( filename=config["logfile"], 67 | level=log_level_map[config["level"]], 68 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 69 | datefmt='%d %H:%M:%S' 70 | ) 71 | log.getLogger('').addHandler(log.StreamHandler()) 72 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 73 | #else: 74 | # print("Log file not available : %s"%(config["logfile"])) 75 | return global_config 76 | -------------------------------------------------------------------------------- /raspi/bathroom/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | from platform import system as system_name # Returns the system/OS name 9 | from subprocess import call as system_call # Execute a shell command 10 | 11 | def ping(host): 12 | """ 13 | Returns True if host (str) responds to a ping request. 14 | Remember that a host may not respond to a ping (ICMP) request even if the host name is valid. 15 | """ 16 | 17 | # Ping command count option as function of OS 18 | param = '-n' if system_name().lower()=='windows' else '-c' 19 | 20 | # Building the command. Ex: "ping -c 1 google.com" 21 | command = ['ping', param, '1', host] 22 | 23 | # Pinging 24 | return system_call(command) == 0 25 | 26 | # -------------------- config -------------------- 27 | def get_local_json(): 28 | """fetches the config.json file in the local directory 29 | if config_hostname.json is found it is used over the default one 30 | """ 31 | config = None 32 | dirname = os.path.dirname(sys.argv[0]) 33 | if(len(dirname) == 0): 34 | dirname = "." 35 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 36 | if(os.path.isfile(config_file)): 37 | print("loading: ",config_file) 38 | config = json.load(open(config_file)) 39 | else: 40 | config_file = dirname+'/'+"config.json" 41 | if(os.path.isfile(config_file)): 42 | print("loading: %s",config_file) 43 | config = json.load(open(config_file)) 44 | else: 45 | print("Fatal error 'config.json' not found") 46 | return config 47 | 48 | # -------------------- config -------------------- 49 | def get_local_nodes(nodes_file): 50 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 51 | return nodes 52 | 53 | def configure_log(logger_name): 54 | global_config = get_local_json() 55 | config = global_config["log"] 56 | log_level_map = { 57 | "Debug" :10, 58 | "Info" :20, 59 | "Warning" :30, 60 | "Error" :40, 61 | "Critical" :50 62 | } 63 | #if(os.path.isfile(config["logfile"])): 64 | for handler in log.root.handlers[:]: 65 | log.root.removeHandler(handler) 66 | log.basicConfig( filename=config["logfile"], 67 | level=log_level_map[config["level"]], 68 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 69 | datefmt='%d %H:%M:%S' 70 | ) 71 | log.getLogger('').addHandler(log.StreamHandler()) 72 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 73 | #else: 74 | # print("Log file not available : %s"%(config["logfile"])) 75 | return global_config 76 | -------------------------------------------------------------------------------- /raspi/home_status/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | from platform import system as system_name # Returns the system/OS name 9 | from subprocess import call as system_call # Execute a shell command 10 | 11 | def ping(host): 12 | """ 13 | Returns True if host (str) responds to a ping request. 14 | Remember that a host may not respond to a ping (ICMP) request even if the host name is valid. 15 | """ 16 | 17 | # Ping command count option as function of OS 18 | param = '-n' if system_name().lower()=='windows' else '-c' 19 | 20 | # Building the command. Ex: "ping -c 1 google.com" 21 | command = ['ping', param, '1', host] 22 | 23 | # Pinging 24 | return system_call(command) == 0 25 | 26 | # -------------------- config -------------------- 27 | def get_local_json(): 28 | """fetches the config.json file in the local directory 29 | if config_hostname.json is found it is used over the default one 30 | """ 31 | config = None 32 | dirname = os.path.dirname(sys.argv[0]) 33 | if(len(dirname) == 0): 34 | dirname = "." 35 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 36 | if(os.path.isfile(config_file)): 37 | print("loading: ",config_file) 38 | config = json.load(open(config_file)) 39 | else: 40 | config_file = dirname+'/'+"config.json" 41 | if(os.path.isfile(config_file)): 42 | print("loading: %s",config_file) 43 | config = json.load(open(config_file)) 44 | else: 45 | print("Fatal error 'config.json' not found") 46 | return config 47 | 48 | # -------------------- config -------------------- 49 | def get_local_nodes(nodes_file): 50 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 51 | return nodes 52 | 53 | def configure_log(logger_name): 54 | global_config = get_local_json() 55 | config = global_config["log"] 56 | log_level_map = { 57 | "Debug" :10, 58 | "Info" :20, 59 | "Warning" :30, 60 | "Error" :40, 61 | "Critical" :50 62 | } 63 | #if(os.path.isfile(config["logfile"])): 64 | for handler in log.root.handlers[:]: 65 | log.root.removeHandler(handler) 66 | log.basicConfig( filename=config["logfile"], 67 | level=log_level_map[config["level"]], 68 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 69 | datefmt='%d %H:%M:%S' 70 | ) 71 | log.getLogger('').addHandler(log.StreamHandler()) 72 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 73 | #else: 74 | # print("Log file not available : %s"%(config["logfile"])) 75 | return global_config 76 | -------------------------------------------------------------------------------- /raspi/milight/milight_gateway.py: -------------------------------------------------------------------------------- 1 | #https://pypi.python.org/pypi/paho-mqtt/1.1 2 | import paho.mqtt.client as mqtt 3 | import json 4 | #https://github.com/McSwindler/python-milight 5 | import milight 6 | from milight import Command 7 | #just to get host name 8 | import socket 9 | from time import sleep 10 | from math import ceil 11 | import logging as log 12 | import sys,os 13 | import cfg 14 | 15 | def on_connect(lclient, userdata, flags, rc): 16 | topic_sub = "Nodes/+/dimmer" 17 | lclient.subscribe(topic_sub) 18 | log.info("Subscribed to: "+topic_sub) 19 | 20 | def on_message(client, userdata, msg): 21 | topic_parts = msg.topic.split('/') 22 | if(len(topic_parts) == 3): 23 | nodeid = topic_parts[1] 24 | if(nodeid in config["mapping"]): 25 | device_name = config["mapping"][nodeid]["device"] 26 | channel = config["mapping"][nodeid]["channel"] 27 | dimm_val = int(ceil(float(msg.payload))) 28 | if(dimm_val > 100): 29 | dimm_val = 100 30 | log.debug( "Action to Node: "+nodeid + 31 | " ; through gateway: "+device_name + 32 | " ; on channel: "+str(channel) + 33 | " ; set value: "+str(dimm_val) 34 | ) 35 | controller = milight_controllers[device_name] 36 | if(dimm_val == 0): 37 | controller.send(light.off(channel)) 38 | elif(dimm_val == 1): 39 | controller.send(light.off(channel)) 40 | sleep(0.100)#100 ms 41 | controller.send(Command(night_mode[channel])) 42 | else: 43 | controller.send(light.brightness(dimm_val,channel)) 44 | else: 45 | log.warning("Node "+nodeid+" route unknown") 46 | else: 47 | log.error("topic: "+msg.topic + "size not matching") 48 | 49 | 50 | def mqtt_connect_retries(client): 51 | connected = False 52 | while(not connected): 53 | try: 54 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 55 | connected = True 56 | log.info( "mqtt connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 57 | except socket.error: 58 | log.error("socket.error will try a reconnection in 10 s") 59 | sleep(10) 60 | return 61 | 62 | # -------------------- main -------------------- 63 | config = cfg.configure_log(__file__) 64 | 65 | # -------------------- Milight Client -------------------- 66 | milight_controllers = {} 67 | for device_name,device in config["devices"].items(): 68 | milight_controllers[device_name] = milight.MiLight(device) 69 | 70 | #light = milight.LightBulb(['rgbw','white','rgb']) 71 | light = milight.LightBulb(['rgbw']) 72 | night_mode = [0xC1, 0xC6, 0xC8, 0xCA, 0xCC] 73 | # -------------------- Mqtt Client -------------------- 74 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 75 | client = mqtt.Client(client_id=cid) 76 | client.on_connect = on_connect 77 | client.on_message = on_message 78 | 79 | mqtt_connect_retries(client) 80 | 81 | client.loop_forever() 82 | 83 | -------------------------------------------------------------------------------- /boards/nrf52_sensortag.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF52_SENSOR_TAG_H 41 | #define NRF52_SENSOR_TAG_H 42 | 43 | //this board design can be found under the $(PROJ_DIR)/pcb folder 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include "nrf_gpio.h" 50 | 51 | // This LED actually does not exist but the pio can be used for debug 52 | #define LEDS_NUMBER 1 53 | 54 | #define LED_START 11 55 | #define LED_RGB_RED 11 56 | #define LED_STOP 11 57 | 58 | #define LEDS_ACTIVE_STATE 0 59 | 60 | #define LEDS_INV_MASK LEDS_MASK 61 | 62 | #define BSP_LED_0 LED_RGB_RED 63 | 64 | #define LEDS_LIST { LED_RGB_RED} 65 | 66 | #define BUTTONS_NUMBER 0 67 | 68 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 69 | 70 | #define BUTTONS_ACTIVE_STATE 0 71 | 72 | #define BUTTONS_LIST { } 73 | 74 | #define I2C_SCL 29 75 | #define I2C_SDA 30 76 | 77 | #define SENSOR_INT 31 78 | 79 | #define RX_PIN_NUMBER 7 80 | #define TX_PIN_NUMBER 6 81 | #define HWFC false 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /*NRF52_SENSOR_TAG_H*/ 89 | -------------------------------------------------------------------------------- /raspi/heat/heat.py: -------------------------------------------------------------------------------- 1 | #https://github.com/studioimaginaire/phue 2 | 3 | 4 | #https://pypi.python.org/pypi/paho-mqtt/1.1 5 | import paho.mqtt.client as mqtt 6 | import json 7 | from time import sleep 8 | import logging as log 9 | import sys,os 10 | import cfg 11 | from mqtt import mqtt_start 12 | 13 | eurotronic_system_mode = { 14 | "mirror display":1, 15 | "boost":2, 16 | "disable open window":4, 17 | "set open window":5, 18 | "child protection":7 19 | } 20 | 21 | def heater_notify(name,command): 22 | topic = config["heatings"][name]["topic"] 23 | json_msg = {"eurotronic_system_mode":2**(eurotronic_system_mode[command])} 24 | text_msg = json.dumps(json_msg) 25 | clientMQTT.publish(topic,text_msg) 26 | return 27 | 28 | def check_all_contacts(apertures): 29 | ''' if any is open then all are open and contact => False''' 30 | res = True 31 | for name,aperture in apertures.items(): 32 | if(aperture == False): 33 | res = False 34 | #print(f"res={res} for {apertures}") 35 | return res 36 | 37 | def window_open(aperture,payload): 38 | global state 39 | sensor = json.loads(payload) 40 | log.debug(f"{aperture} => contact = {sensor['contact']}") 41 | heater = topic_to_heater[aperture] 42 | prev_all_contacts = check_all_contacts(state[heater]["apertures"]) 43 | state[heater]["apertures"][aperture] = sensor["contact"] 44 | current_all_contacts = check_all_contacts(state[heater]["apertures"]) 45 | if(current_all_contacts != prev_all_contacts): 46 | if(current_all_contacts): 47 | heater_notify(heater,"disable open window") 48 | log.info(f"state changed : {heater} => disable open window") 49 | else: 50 | heater_notify(heater,"set open window") 51 | log.info(f"state changed : {heater} => set open window") 52 | else: 53 | log.debug(f" no state change all_contact = {current_all_contacts}") 54 | return 55 | 56 | 57 | def mqtt_on_message(client, userdata, msg): 58 | try: 59 | topic_parts = msg.topic.split('/') 60 | if(len(topic_parts) == 2): 61 | name = topic_parts[1] 62 | if(name in topics_list): 63 | window_open(name,msg.payload) 64 | else: 65 | log.error(f"topic: {msg.topic} size not matching") 66 | except Exception as e: 67 | log.error("mqtt_on_message> Exception :%s"%e) 68 | return 69 | 70 | # -------------------- main -------------------- 71 | config = cfg.configure_log(__file__) 72 | 73 | state = {} 74 | topics_list = [] 75 | topic_to_heater = {} 76 | for name,heater in config["heatings"].items(): 77 | state[name] = {} 78 | state[name]["apertures"] = {} 79 | for aperture in heater["Apertures"]: 80 | state[name]["apertures"][aperture] = True 81 | topics_list.append(aperture) 82 | topic_to_heater[aperture] = name 83 | 84 | 85 | # -------------------- Mqtt Client -------------------- 86 | #will start a separate thread for looping 87 | clientMQTT = mqtt_start(config,mqtt_on_message,True) 88 | 89 | 90 | 91 | 92 | while(True): 93 | sleep(0.2) 94 | #The MQTT keeps looping on a thead 95 | #All there is to do here is not to exit 96 | -------------------------------------------------------------------------------- /boards/nrf52832_rovarm.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF52_SENSOR_TAG_H 41 | #define NRF52_SENSOR_TAG_H 42 | 43 | //this board design can be found under the $(PROJ_DIR)/pcb folder 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include "nrf_gpio.h" 50 | 51 | // This LED actually does not exist but the pio can be used for debug 52 | #define LEDS_NUMBER 1 53 | 54 | #define LED_START 11 55 | #define LED_RGB_RED 11 56 | #define LED_STOP 11 57 | 58 | #define LEDS_ACTIVE_STATE 0 59 | 60 | #define LEDS_INV_MASK LEDS_MASK 61 | 62 | #define BSP_LED_0 LED_RGB_RED 63 | 64 | #define LEDS_LIST { LED_RGB_RED} 65 | 66 | #define BUTTONS_NUMBER 0 67 | 68 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 69 | 70 | #define BUTTONS_ACTIVE_STATE 0 71 | 72 | #define BUTTONS_LIST { } 73 | 74 | #define GPIO_M_P1 31 75 | #define GPIO_M_P2 29 76 | #define GPIO_M_P3 30 77 | #define GPIO_M_EN 11 78 | 79 | #define RX_PIN_NUMBER 7 80 | #define TX_PIN_NUMBER 6 81 | #define HWFC false 82 | 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /*NRF52_SENSOR_TAG_H*/ 89 | -------------------------------------------------------------------------------- /boards/nrf52_dongle.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef NRF52_SENSOR_TAG_H 41 | #define NRF52_SENSOR_TAG_H 42 | 43 | //this board design can be found under the $(PROJ_DIR)/pcb folder 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include "nrf_gpio.h" 50 | 51 | // This LED actually does not exist but the pio can be used for debug 52 | #define LEDS_NUMBER 2 53 | 54 | #define LED_START 28 55 | #define LED_1 28 56 | #define LED_2 29 57 | #define LED_STOP 29 58 | 59 | #define LEDS_ACTIVE_STATE 0 60 | 61 | #define LEDS_INV_MASK LEDS_MASK 62 | 63 | #define BSP_LED_0 LED_1 64 | #define BSP_LED_1 LED_2 65 | 66 | #define LEDS_LIST { LED_1, LED_2} 67 | 68 | #define BUTTONS_NUMBER 0 69 | 70 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 71 | 72 | #define BUTTONS_ACTIVE_STATE 0 73 | 74 | #define BUTTONS_LIST { } 75 | 76 | #define RX_PIN_NUMBER 5 77 | #define TX_PIN_NUMBER 6 78 | #define CTS_PIN_NUMBER 7 79 | #define RTS_PIN_NUMBER 8 80 | #define HWFC false 81 | 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /*NRF52_SENSOR_TAG_H*/ 88 | -------------------------------------------------------------------------------- /raspi/ruler/ruler.py: -------------------------------------------------------------------------------- 1 | import paho.mqtt.client as mqtt 2 | import datetime 3 | import logging as log 4 | import cfg 5 | from time import sleep,time 6 | import json 7 | import rules 8 | import socket 9 | from vectors import Vector 10 | 11 | # -------------------- mqtt events -------------------- 12 | def on_connect(lclient, userdata, flags, rc): 13 | log.info("mqtt connected with result code "+str(rc)) 14 | for rule_name,rule in config["rules"].items(): 15 | if(rule["enable"]): 16 | log.info("Subscription for rule:%s %s -> %s",rule_name,rule["input"],rule["output"]) 17 | lclient.subscribe(rule["input"]) 18 | #Here custom subscriptions can be added 19 | lclient.subscribe("jNodes/+/alive") 20 | 21 | def get_min_rssi(j_payload): 22 | res = None 23 | for key, value in j_payload.items(): 24 | if key.startswith('rx'): 25 | if 'rssi' in value: 26 | rssi = int(value["rssi"]) 27 | if(res is None) or (res > rssi): 28 | res = rssi 29 | return res 30 | 31 | def on_message(client, userdata, msg): 32 | topic_parts = msg.topic.split('/') 33 | for rule_name,rule in config["rules"].items(): 34 | if msg.topic == rule["input"]: 35 | if(rule["enable"]): 36 | #call the Fuction with the same name as the Rule 37 | payload = getattr(rules,rule_name)(msg.payload) 38 | #payload = rules.Upstairs_Heat(msg.payload) 39 | if(payload != None): 40 | clientMQTT.publish(rule["output"],payload) 41 | #Here Custom Rules can be run 42 | if (len(topic_parts)==3) and (topic_parts[0] == "jNodes") and (topic_parts[2]=="alive"): 43 | j_payload = json.loads(msg.payload) 44 | min_rssi = get_min_rssi(j_payload) 45 | min_rssi_text = json.dumps(min_rssi) 46 | if(min_rssi_text != None): 47 | topic = "Nodes/"+topic_parts[1]+"/rssi" 48 | clientMQTT.publish(topic,min_rssi_text) 49 | 50 | 51 | def ruler_loop_forever(): 52 | while(True): 53 | sleep(10) 54 | return 55 | 56 | 57 | def mqtt_start(): 58 | def mqtt_connect_retries(client): 59 | connected = False 60 | while(not connected): 61 | try: 62 | client.connect(config["mqtt"]["host"], config["mqtt"]["port"], config["mqtt"]["keepalive"]) 63 | connected = True 64 | log.info( "mqtt connected to "+config["mqtt"]["host"]+":"+str(config["mqtt"]["port"])+" with id: "+ cid ) 65 | except socket.error: 66 | log.error("socket.error will try a reconnection in 10 s") 67 | sleep(10) 68 | return 69 | cid = config["mqtt"]["client_id"] +"_"+socket.gethostname() 70 | client = mqtt.Client(client_id=cid) 71 | clientMQTT = mqtt.Client() 72 | clientMQTT.on_connect = on_connect 73 | clientMQTT.on_message = on_message 74 | mqtt_connect_retries(clientMQTT) 75 | clientMQTT.loop_start() 76 | return clientMQTT 77 | 78 | 79 | 80 | 81 | # -------------------- main -------------------- 82 | config = cfg.configure_log(__file__) 83 | 84 | #will start a separate thread for looping 85 | clientMQTT = mqtt_start() 86 | 87 | #loop forever 88 | ruler_loop_forever() 89 | 90 | 91 | -------------------------------------------------------------------------------- /raspi/conbee/cfg.py: -------------------------------------------------------------------------------- 1 | import sys,os 2 | import json 3 | import logging as log 4 | import socket 5 | from collections import OrderedDict 6 | import datetime 7 | 8 | from platform import system as system_name # Returns the system/OS name 9 | from subprocess import call as system_call # Execute a shell command 10 | 11 | def ping(host): 12 | """ 13 | Returns True if host (str) responds to a ping request. 14 | Remember that a host may not respond to a ping (ICMP) request even if the host name is valid. 15 | """ 16 | 17 | # Ping command count option as function of OS 18 | param = '-n' if system_name().lower()=='windows' else '-c' 19 | 20 | # Building the command. Ex: "ping -c 1 google.com" 21 | command = ['ping', param, '1', host] 22 | 23 | # Pinging 24 | return system_call(command) == 0 25 | 26 | # -------------------- config -------------------- 27 | def get_local_json(): 28 | """fetches the config.json file in the local directory 29 | if config_hostname.json is found it is used over the default one 30 | """ 31 | config = None 32 | dirname = os.path.dirname(sys.argv[0]) 33 | if(len(dirname) == 0): 34 | dirname = "." 35 | config_file = dirname+'/'+"config_"+socket.gethostname()+".json" 36 | if(os.path.isfile(config_file)): 37 | print("loading: ",config_file) 38 | config = json.load(open(config_file)) 39 | else: 40 | config_file = dirname+'/'+"config.json" 41 | if(os.path.isfile(config_file)): 42 | print("loading: %s",config_file) 43 | config = json.load(open(config_file)) 44 | else: 45 | print("Fatal error 'config.json' not found") 46 | return config 47 | 48 | # -------------------- config -------------------- 49 | def get_local_nodes(nodes_file): 50 | nodes = json.load(open(nodes_file),object_pairs_hook=OrderedDict) 51 | return nodes 52 | 53 | def configure_log(logger_name): 54 | global_config = get_local_json() 55 | config = global_config["log"] 56 | log_level_map = { 57 | "Debug" :10, 58 | "Info" :20, 59 | "Warning" :30, 60 | "Error" :40, 61 | "Critical" :50 62 | } 63 | #if(os.path.isfile(config["logfile"])): 64 | for handler in log.root.handlers[:]: 65 | log.root.removeHandler(handler) 66 | log.basicConfig( filename=config["logfile"], 67 | level=log_level_map[config["level"]], 68 | format='%(asctime)s %(name)s %(levelname)-8s %(message)s', 69 | datefmt='%d %H:%M:%S' 70 | ) 71 | log.getLogger('').addHandler(log.StreamHandler()) 72 | log.info("====> '%s' started logging with level '%s' @ '%s'"%(logger_name,config["level"],str(datetime.datetime.utcnow()))) 73 | #else: 74 | # print("Log file not available : %s"%(config["logfile"])) 75 | return global_config 76 | 77 | 78 | def get_node_id_from_name(name,nodes): 79 | res ="" 80 | for key,val in nodes.items(): 81 | if "name" in val: 82 | if val["name"] == name: 83 | res = key 84 | return res 85 | 86 | def get_first_key_from_param(param,match,mapdict): 87 | res ="" 88 | for key,entry in mapdict.items(): 89 | if param in entry: 90 | if entry[param] == match: 91 | res = key 92 | return res 93 | return res 94 | -------------------------------------------------------------------------------- /boards/nrf52_buttons.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef BOARD_NRF52_BUTTONS_H 41 | #define BOARD_NRF52_BUTTONS_H 42 | 43 | //this board design can be found under the $(PROJ_DIR)/pcb folder 44 | 45 | #ifdef __cplusplus 46 | extern "C" { 47 | #endif 48 | 49 | #include "nrf_gpio.h" 50 | 51 | // This LED actually does not exist but the pio can be used for debug 52 | #define LEDS_NUMBER 0 53 | 54 | #define LEDS_ACTIVE_STATE 0 55 | 56 | #define LEDS_LIST { } 57 | 58 | #define BUTTONS_NUMBER 6 59 | 60 | 61 | #define BUTTON_1 14 62 | #define BUTTON_2 12 63 | #define BUTTON_3 11 64 | #define BUTTON_4 29 65 | #define BUTTON_5 30 66 | #define BUTTON_6 31 67 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 68 | 69 | #define BUTTONS_ACTIVE_STATE 0 70 | 71 | #define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4, BUTTON_5, BUTTON_6 } 72 | 73 | #define BSP_BUTTON_0 BUTTON_1 74 | #define BSP_BUTTON_1 BUTTON_2 75 | #define BSP_BUTTON_2 BUTTON_3 76 | #define BSP_BUTTON_3 BUTTON_4 77 | #define BSP_BUTTON_4 BUTTON_5 78 | #define BSP_BUTTON_5 BUTTON_6 79 | 80 | 81 | #define I2C_SCL 29 82 | #define I2C_SDA 30 83 | 84 | #define SENSOR_INT 31 85 | 86 | #define RX_PIN_NUMBER 7 87 | #define TX_PIN_NUMBER 6 88 | #define HWFC false 89 | 90 | 91 | #ifdef __cplusplus 92 | } 93 | #endif 94 | 95 | #endif /*BOARD_NRF52_BUTTONS_H*/ 96 | -------------------------------------------------------------------------------- /raspi/influx/readme.md: -------------------------------------------------------------------------------- 1 | 2 | # influx queries examples 3 | 4 | SELECT "temperature" FROM "node91" WHERE $timeFilter 5 | 6 | 7 | SELECT mean("battery") FROM "node78" WHERE $timeFilter GROUP BY time(3h) 8 | SELECT mean("battery") FROM "node78" WHERE $timeFilter GROUP BY time(24h) 9 | 10 | 11 | Show Field Keys 12 | drop MEASUREMENT "motion button" 13 | 14 | # Install on the Raspberry pi 15 | sources: 16 | - https://gist.github.com/boseji/bb71910d43283a1b84ab200bcce43c26 17 | - https://docs.influxdata.com/influxdb/v1.4/introduction/getting_started/ 18 | - https://github.com/influxdata/influxdb/blob/master/QUERIES.md 19 | 20 | ``` 21 | sudo apt install apt-transport-https 22 | echo "deb https://repos.influxdata.com/debian stretch stable" | sudo tee /etc/apt/sources.list.d/influxdb.list 23 | sudo apt-get update 24 | 25 | sudo apt-get install influxdb 26 | 27 | ``` 28 | 29 | ### config 30 | Default 31 | ``` 32 | sudo nano /etc/influxdb/influxdb.conf 33 | ``` 34 | directly from the repo 35 | ``` 36 | INFLUXDB_CONFIG_PATH=/home/pi/IoT_Frameworks/config/influxdb/influxdb.conf 37 | ``` 38 | 39 | ### start the service 40 | ``` 41 | sudo systemctl start influxdb 42 | ``` 43 | 44 | ### help reminder, see getting started link for more 45 | ``` 46 | influx -precision rfc3339 47 | CREATE DATABASE mydb, 48 | SHOW DATABASES 49 | SHOW SERIES on raspiStatus 50 | USE mydb 51 | 52 | DROP DATABASE mydb 53 | 54 | cpu,host=serverA,region=us_west value=0.64 55 | 56 | SHOW FIELD KEYS FROM "cpu_temp" 57 | SHOW TAG KEYS FROM "cpu_temp" 58 | SHOW TAG VALUES FROM "cpu_temp" WITH KEY="host" 59 | 60 | SELECT * FROM "cpu_temp" WHERE "host" = 'ioserv' 61 | 62 | SELECT "power" FROM "node30" WHERE time > '2017-12-24T12:33:00Z' AND time < '2017-12-24T15:34:10Z' 63 | DELETE FROM "node37" WHERE time > '2017-12-24T12:33:00Z' AND time < '2017-12-24T15:34:10Z' 64 | ``` 65 | ### Nodes posts 66 | ``` 67 | post = [ 68 | { 69 | "measurement": "node6", 70 | "time": datetime.datetime.utcnow(), 71 | "fields": { 72 | "temperature": value 73 | } 74 | } 75 | ] 76 | ``` 77 | ### Grafana Queries 78 | ``` 79 | SELECT "temperature" FROM "node6" WHERE $timeFilter 80 | ``` 81 | ### Raspi status posts 82 | ``` 83 | posts = [ 84 | { 85 | "measurement": "cpu_load", 86 | "time": tnow, 87 | "tags":{ 88 | "host":hostname 89 | }, 90 | "fields": { 91 | "value": float(rasp.getCPU_Avg1min()) 92 | } 93 | } 94 | ] 95 | ``` 96 | 97 | ### Raspi queries 98 | ``` 99 | SELECT "value" FROM "cpu_load" 100 | ``` 101 | 102 | ### purse wrong data types 103 | 104 | >influx 105 | use meshNodes 106 | SHOW SERIES 107 | SHOW FIELD KEYS FROM "entrance light" 108 | SELECT "battery" FROM "entrance light" 109 | 110 | DELETE FROM "entrance light" WHERE time > 1543760602123951871 AND time < 1546526296817206017 111 | 112 | does not drop the types 113 | 114 | DROP MEASUREMENT "bed weather" 115 | 116 | SHOW FIELD KEYS FROM "entrance light" 117 | 118 | drops the types, but still present after exit and return 119 | 120 | DELETE from "entrance light" where time > 0 121 | 122 | drops the types permanently 123 | DROP SERIES FROM "entrance light" 124 | 125 | does not work : 126 | 127 | drop series from "bed weather" where battery='100.00'; 128 | delete series from "bed weather" where battery='100.00'; 129 | 130 | step: 131 | * retrieve measurements 132 | * modify 133 | * re-insert 134 | -------------------------------------------------------------------------------- /boards/custom840.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef CUSTOM840_H 41 | #define CUSTOM840_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #include "nrf_gpio.h" 48 | 49 | // LED definitions for PCA10059 50 | // Each LED color is considered a separate LED 51 | #define LEDS_NUMBER 4 52 | 53 | #define LED1_G NRF_GPIO_PIN_MAP(0,6) 54 | #define LED2_R NRF_GPIO_PIN_MAP(0,8) 55 | #define LED2_G NRF_GPIO_PIN_MAP(1,9) 56 | #define LED2_B NRF_GPIO_PIN_MAP(0,12) 57 | 58 | #define LED_1 LED1_G 59 | #define LED_2 LED2_R 60 | #define LED_3 LED2_G 61 | #define LED_4 LED2_B 62 | 63 | #define LEDS_ACTIVE_STATE 0 64 | 65 | #define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 } 66 | 67 | #define LEDS_INV_MASK LEDS_MASK 68 | 69 | #define BSP_LED_0 LED_1 70 | #define BSP_LED_1 LED_2 71 | #define BSP_LED_2 LED_3 72 | #define BSP_LED_3 LED_4 73 | 74 | // There is only one button for the application 75 | // as the second button is used for a RESET. 76 | #define BUTTONS_NUMBER 1 77 | 78 | #define BUTTON_1 NRF_GPIO_PIN_MAP(1,6) 79 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 80 | 81 | #define BUTTONS_ACTIVE_STATE 0 82 | 83 | #define BUTTONS_LIST { BUTTON_1 } 84 | 85 | #define BSP_BUTTON_0 BUTTON_1 86 | 87 | #define BSP_SELF_PINRESET_PIN NRF_GPIO_PIN_MAP(0,19) 88 | 89 | #define TX_PIN_NUMBER NRF_GPIO_PIN_MAP(0,10) 90 | #define RX_PIN_NUMBER NRF_GPIO_PIN_MAP(0,9) 91 | #define CTS_PIN_NUMBER NRF_GPIO_PIN_MAP(1,00) 92 | #define RTS_PIN_NUMBER NRF_GPIO_PIN_MAP(0,24) 93 | #define HWFC false 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif // CUSTOM840_H 100 | -------------------------------------------------------------------------------- /boards/pca10059.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA 3 | * 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without modification, 7 | * are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, this 10 | * list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form, except as embedded into a Nordic 13 | * Semiconductor ASA integrated circuit in a product or a software update for 14 | * such product, must reproduce the above copyright notice, this list of 15 | * conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * 3. Neither the name of Nordic Semiconductor ASA nor the names of its 19 | * contributors may be used to endorse or promote products derived from this 20 | * software without specific prior written permission. 21 | * 22 | * 4. This software, with or without modification, must only be used with a 23 | * Nordic Semiconductor ASA integrated circuit. 24 | * 25 | * 5. Any software provided in binary form under this license must not be reverse 26 | * engineered, decompiled, modified and/or disassembled. 27 | * 28 | * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS 29 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 30 | * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE 31 | * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE 32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 34 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 37 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | * 39 | */ 40 | #ifndef PCA10059_H 41 | #define PCA10059_H 42 | 43 | #ifdef __cplusplus 44 | extern "C" { 45 | #endif 46 | 47 | #include "nrf_gpio.h" 48 | 49 | // LED definitions for PCA10059 50 | // Each LED color is considered a separate LED 51 | #define LEDS_NUMBER 4 52 | 53 | #define LED1_G NRF_GPIO_PIN_MAP(0,6) 54 | #define LED2_R NRF_GPIO_PIN_MAP(0,8) 55 | #define LED2_G NRF_GPIO_PIN_MAP(1,9) 56 | #define LED2_B NRF_GPIO_PIN_MAP(0,12) 57 | 58 | #define LED_1 LED1_G 59 | #define LED_2 LED2_R 60 | #define LED_3 LED2_G 61 | #define LED_4 LED2_B 62 | 63 | #define LEDS_ACTIVE_STATE 0 64 | 65 | #define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 } 66 | 67 | #define LEDS_INV_MASK LEDS_MASK 68 | 69 | #define BSP_LED_0 LED_1 70 | #define BSP_LED_1 LED_2 71 | #define BSP_LED_2 LED_3 72 | #define BSP_LED_3 LED_4 73 | 74 | // There is only one button for the application 75 | // as the second button is used for a RESET. 76 | #define BUTTONS_NUMBER 1 77 | 78 | #define BUTTON_1 NRF_GPIO_PIN_MAP(1,6) 79 | #define BUTTON_PULL NRF_GPIO_PIN_PULLUP 80 | 81 | #define BUTTONS_ACTIVE_STATE 0 82 | 83 | #define BUTTONS_LIST { BUTTON_1 } 84 | 85 | #define BSP_BUTTON_0 BUTTON_1 86 | 87 | #define BSP_SELF_PINRESET_PIN NRF_GPIO_PIN_MAP(0,19) 88 | 89 | #define TX_PIN_NUMBER NRF_GPIO_PIN_MAP(0,10) 90 | #define RX_PIN_NUMBER NRF_GPIO_PIN_MAP(0,9) 91 | #define CTS_PIN_NUMBER NRF_GPIO_PIN_MAP(1,00) 92 | #define RTS_PIN_NUMBER NRF_GPIO_PIN_MAP(0,24) 93 | #define HWFC false 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif // PCA10059_H 100 | -------------------------------------------------------------------------------- /drivers/mesh.h: -------------------------------------------------------------------------------- 1 | #ifndef __MESH_H__ 2 | #define __MESH_H__ 3 | 4 | 5 | #include 6 | #include 7 | 8 | //should match NRF_ESB_MAX_PAYLOAD_LENGTH 9 | #define MAX_MESH_MESSAGE_SIZE (NRF_ESB_MAX_PAYLOAD_LENGTH-4) 10 | 11 | typedef struct 12 | { 13 | uint8_t control; 14 | uint8_t pid; 15 | uint8_t source; 16 | uint8_t dest; 17 | int8_t rssi; //Radio Signal Strength Indication 18 | uint8_t payload_length; 19 | uint8_t *payload; 20 | }message_t; 21 | 22 | extern const char * const pid_name[]; 23 | 24 | //------------------------- Mesh Functions Identifiers ------------------------- 25 | 26 | #define Mesh_Pid_Alive 0x05 27 | #define Mesh_Pid_Reset 0x04 28 | #define Mesh_Pid_Button 0x06 29 | 30 | //light u32 bit (lux x 1000) 31 | #define Mesh_Pid_Light 0x07 32 | #define Mesh_Pid_Temperature 0x08 33 | //bme280 no more with uncalibrated params 34 | #define Mesh_Pid_bme 0x0A 35 | //following rgb is led color control 36 | #define Mesh_Pid_led_rgb 0x0B 37 | #define Mesh_Pid_light_rgb 0x0E 38 | #define Mesh_Pid_Humidity 0x11 39 | #define Mesh_Pid_Pressure 0x12 40 | #define Mesh_Pid_accell 0x13 41 | #define Mesh_Pid_new_light 0x14 42 | #define Mesh_Pid_Battery 0x15 43 | #define Mesh_Pid_Text 0x16 44 | #define Mesh_Pid_MQTT 0x17 45 | #define Mesh_Pid_ExecuteCmd 0xEC 46 | 47 | #define MESH_Broadcast_Header_Length 4 48 | #define MESH_P2P_Header_Length 5 49 | 50 | #define MESH_cmd_node_id_set 0x01 51 | #define MESH_cmd_node_id_get 0x02 52 | #define MESH_cmd_rf_chan_set 0x03 53 | #define MESH_cmd_rf_chan_get 0x04 54 | #define MESH_cmd_tx_power_set 0x05 55 | #define MESH_cmd_tx_power_get 0x06 56 | #define MESH_cmd_bitrate_set 0x07 57 | #define MESH_cmd_bitrate_get 0x08 58 | #define MESH_cmd_crc_set 0x09 59 | #define MESH_cmd_crc_get 0x0A 60 | 61 | //------------------------- Mesh Macros ------------------------- 62 | 63 | #define MESH_IS_BROADCAST(val) ((val & 0x80) == 0x80) 64 | #define MESH_IS_PEER2PEER(val) ((val & 0x80) == 0x00) 65 | //Ack if bits 1,2 == 1,0 => MASK 0x60, VAL 0x40 66 | #define MESH_IS_ACKNOWLEDGE(val) ((val & 0x60) == 0x40) 67 | #define MESH_WANT_ACKNOWLEDGE(val) ((val & 0xF0) == 0x70) 68 | #define MESH_IS_RESPONSE(val) ((val & 0xF0) == 0x00) 69 | 70 | 71 | //------------------------- Mesh Core ------------------------- 72 | 73 | typedef void (*app_mesh_rf_handler_t)(message_t*); 74 | 75 | typedef void (*app_mesh_cmd_handler_t)(const char*,uint8_t); 76 | 77 | uint8_t mesh_channel(); 78 | 79 | uint32_t mesh_init(app_mesh_rf_handler_t rf_handler,app_mesh_cmd_handler_t cmd_handler); 80 | 81 | void mesh_execute_cmd(uint8_t*data,uint8_t size,bool is_rf_request,uint8_t rf_nodeid); 82 | 83 | //------------------------- Mesh protocol ------------------------- 84 | 85 | void mesh_consume_rx_messages(); 86 | 87 | void mesh_wait_tx(); 88 | 89 | void mesh_tx_reset(); 90 | uint32_t mesh_tx_alive(); 91 | 92 | void mesh_bcast_data(uint8_t pid,uint8_t * data,uint8_t size); 93 | void mesh_bcast_text(char *text); 94 | void mesh_ttl_set(uint8_t ttl); 95 | 96 | uint32_t mesh_tx_button(uint8_t state); 97 | void mesh_tx_light(uint32_t light); 98 | void mesh_tx_battery(uint16_t voltage); 99 | void mesh_tx_bme(int32_t temp,uint32_t hum,uint32_t press); 100 | 101 | void mesh_parse(message_t* msg,char * p_msg); 102 | void mesh_parse_raw(message_t* msg,char * p_msg); 103 | void mesh_parse_bytes(message_t* msg,char * p_msg); 104 | 105 | //------------------------- Mesh Commander ------------------------- 106 | 107 | void mesh_text_request(const char*text,uint8_t length); 108 | 109 | //-------------------------- Parsers ------------------------------- 110 | int rx_accell(char * p_msg,uint8_t*data,uint8_t size); 111 | int rx_gyro(char * p_msg,uint8_t*data,uint8_t size); 112 | 113 | 114 | #endif /*__MESH_H__*/ 115 | -------------------------------------------------------------------------------- /raspi/leds_panel/leds_panel.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import json 3 | from mqtt import mqtt_start 4 | import cfg 5 | from colour import Color 6 | from time import sleep 7 | 8 | panel_name = "curvy" 9 | 10 | def interpolate(col1,col2,coeff): 11 | res = Color(rgb=( (col1.get_red() * (1-coeff)) + (col2.get_red() * coeff), 12 | (col1.get_green() * (1-coeff)) + (col2.get_green() * coeff), 13 | (col1.get_blue() * (1-coeff)) + (col2.get_blue() * coeff) 14 | ) 15 | ) 16 | return res 17 | 18 | def pixels_all(color): 19 | topic = "esp/"+panel_name+"/pixels/all" 20 | panel = {} 21 | panel["red"] = int(color.get_red()*255) 22 | panel["green"] = int(color.get_green()*255) 23 | panel["blue"] = int(color.get_blue()*255) 24 | clientMQTT.publish(topic,json.dumps(panel)) 25 | return 26 | 27 | def pixels_one(index,color): 28 | topic = "esp/"+panel_name+"/pixels/one" 29 | panel = {} 30 | panel["index"] = index 31 | panel["red"] = int(color.get_red()*255) 32 | panel["green"] = int(color.get_green()*255) 33 | panel["blue"] = int(color.get_blue()*255) 34 | clientMQTT.publish(topic,json.dumps(panel)) 35 | return 36 | 37 | def pixels_list(col_list): 38 | topic = "esp/"+panel_name+"/pixels/list" 39 | panel = {} 40 | rgb_list = [] 41 | for col in col_list: 42 | rgb_list.append(int(col.get_red()*255)) 43 | rgb_list.append(int(col.get_green()*255)) 44 | rgb_list.append(int(col.get_blue()*255)) 45 | panel["leds"] = rgb_list 46 | clientMQTT.publish(topic,json.dumps(panel)) 47 | return 48 | 49 | def panel_off(): 50 | topic = "esp/"+panel_name+"/panel" 51 | panel = {} 52 | panel["action"] = "off" 53 | clientMQTT.publish(topic,json.dumps(panel)) 54 | return 55 | 56 | def panel_flash(color, duration_ms): 57 | topic = "esp/"+panel_name+"/panel" 58 | panel = {} 59 | panel["action"] = "flash" 60 | panel["duration_ms"] = duration_ms 61 | panel["r"] = int(color.get_red()*255) 62 | panel["g"] = int(color.get_green()*255) 63 | panel["b"] = int(color.get_blue()*255) 64 | clientMQTT.publish(topic,json.dumps(panel)) 65 | return 66 | 67 | def panel_wave(color, duration_ms, freq, length): 68 | topic = "esp/"+panel_name+"/panel" 69 | panel = {} 70 | panel["action"] = "wave" 71 | panel["duration_ms"] = duration_ms 72 | panel["freq"] = freq 73 | panel["length"] = length 74 | panel["r"] = int(color.get_red()*255) 75 | panel["g"] = int(color.get_green()*255) 76 | panel["b"] = int(color.get_blue()*255) 77 | clientMQTT.publish(topic,json.dumps(panel)) 78 | return 79 | 80 | def test_range(): 81 | for i in range(5): 82 | pixels_one(i,Color(rgb=(0, 0, 0.1))) 83 | sleep(0.2) 84 | return 85 | 86 | def test_list(): 87 | my_panel = [] 88 | for i in range(4): 89 | my_panel.append(Color(rgb=(0, 0, 1/255))) 90 | pixels_list(my_panel) 91 | return 92 | 93 | def pixels_off(): 94 | pixels_all(Color(rgb=(0, 0, 0))) 95 | return 96 | 97 | def pixels_brightness(val): 98 | pixels_all(Color(rgb=(val, val, val))) 99 | return 100 | 101 | def pixels_blink(): 102 | pixels_brightness(1) 103 | sleep(0.3) 104 | pixels_off() 105 | return 106 | 107 | def test_waves(): 108 | panel_wave( Color(rgb=(0, 10/255, 0)), 800000, 2, 32 ) 109 | sleep(0.3) 110 | panel_wave( Color(rgb=(0,0 ,10/255)), 800000, -3, 32 ) 111 | return 112 | # -------------------- main -------------------- 113 | config = cfg.get_local_json() 114 | #will start a separate thread for looping 115 | clientMQTT = mqtt_start(config,None,False) 116 | 117 | #pixels_all(Color(rgb=(0, 1/255, 0))) 118 | #test_range() 119 | #test_list() 120 | #pixels_blink() 121 | #pixels_off() 122 | #panel_off() 123 | 124 | #panel_flash(Color(rgb=(0, 0, 0))) 125 | 126 | test_waves() 127 | -------------------------------------------------------------------------------- /drivers/max44009.c: -------------------------------------------------------------------------------- 1 | /** @file max44009.c 2 | * 3 | * @author Wassim FILALI 4 | * 5 | * @compiler arm gcc 6 | * 7 | * 8 | * $Date: 29.10.2016 - creation out of refactoring 9 | * $Date: XX.08.2018 - takeover to nRf52 10 | * $Revision: 1 11 | * 12 | */ 13 | 14 | #include "max44009.h" 15 | 16 | #include "math.h" 17 | 18 | #define NRF_LOG_MODULE_NAME max 19 | 20 | #if (MAX_CONFIG_LOG_ENABLED == 1) 21 | #define NRF_LOG_LEVEL MAX_CONFIG_LOG_LEVEL 22 | #define NRF_LOG_INFO_COLOR MAX_CONFIG_INFO_COLOR 23 | #define NRF_LOG_DEBUG_COLOR MAX_CONFIG_DEBUG_COLOR 24 | #else //MAX_CONFIG_LOG_ENABLED 25 | #define NRF_LOG_LEVEL 0 26 | #endif //MAX_CONFIG_LOG_ENABLED 27 | 28 | #include "nrf_log.h" 29 | NRF_LOG_MODULE_REGISTER(); 30 | 31 | 32 | 33 | static const uint8_t address = 0x4A; 34 | static const nrf_drv_twi_t *p_twi = NULL; 35 | 36 | //The MAX44009 does not support auto reg address increment 37 | //reg address have to be sent for every byte either with I²C stop or with a new transaction 38 | uint8_t max44009_read_reg(uint8_t reg) 39 | { 40 | uint8_t res; 41 | ret_code_t err_code; 42 | err_code = nrf_drv_twi_tx(p_twi, address, ®, 1,true); 43 | APP_ERROR_CHECK(err_code); 44 | err_code = nrf_drv_twi_rx(p_twi, address, &res, 1); 45 | APP_ERROR_CHECK(err_code); 46 | //NRF_LOG_DEBUG("@ 0x%02x => 0x%02x", reg,res); 47 | 48 | return res; 49 | } 50 | 51 | uint16_t max44009_read_luxregs() 52 | { 53 | //TODO using transfers can ensure no stop between reads for consistent regs content 54 | return 0; 55 | } 56 | 57 | float max44009_data_to_lux(uint8_t high,uint8_t low) 58 | { 59 | float exponent = (float)(high >> 4); 60 | float mantissa = (float)(((0x0F&high) << 4)+(0x0F & low)); 61 | NRF_LOG_DEBUG("exponent = "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(exponent)); 62 | NRF_LOG_DEBUG("mantissa = "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(mantissa)); 63 | float highval = pow(2,exponent) * mantissa; 64 | NRF_LOG_DEBUG("highval = "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(highval)); 65 | float light_lux = highval * 0.045; 66 | return light_lux; 67 | } 68 | 69 | void max44009_test() 70 | { 71 | NRF_LOG_INFO("-------- test MAX44009 --------"); 72 | uint8_t high,low; 73 | float res; 74 | high = 0b00000000; 75 | low = 0b0001; 76 | res = max44009_data_to_lux(high,low); 77 | NRF_LOG_INFO("0000 0000 0001 => (? 0.045 ) "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(res)); 78 | 79 | high = 0b00000001; 80 | low = 0b0000; 81 | res = max44009_data_to_lux(high,low); 82 | NRF_LOG_INFO("0000 0001 0000 => (? 0.72 ) "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(res)); 83 | 84 | high = 0b00010001; 85 | low = 0b0001; 86 | res = max44009_data_to_lux(high,low); 87 | NRF_LOG_INFO("0001 0001 0001 => (? 1.53 ) "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(res)); 88 | 89 | high = 0b11101111; 90 | low = 0b1111; 91 | res = max44009_data_to_lux(high,low); 92 | NRF_LOG_INFO("1110 1111 1111 => (? 188006 )"NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(res)); 93 | 94 | high = 0b11101111; 95 | low = 0b1110; 96 | res = max44009_data_to_lux(high,low); 97 | NRF_LOG_INFO("1110 1111 1110 => (? 187269 ) "NRF_LOG_FLOAT_MARKER,NRF_LOG_FLOAT(res)); 98 | } 99 | 100 | /** 101 | * @brief reads the light registers with safe overflow re-read 102 | * 103 | * @param l_twi the Two Wire Interface driver instance 104 | * @return uint32_t light in mili-lux 105 | */ 106 | uint32_t max44009_read_light(nrf_drv_twi_t *l_twi) 107 | { 108 | p_twi = l_twi; 109 | uint8_t high = max44009_read_reg(0x03); 110 | uint8_t low = max44009_read_reg(0x04); 111 | uint8_t high1 = max44009_read_reg(0x03); 112 | uint8_t low1 = max44009_read_reg(0x04); 113 | if((high!=high1) || (low!=low1))//error edge encountred, repeat read, won't happen twice in row 114 | { 115 | high = max44009_read_reg(0x03); 116 | low = max44009_read_reg(0x04); 117 | } 118 | uint32_t res = (uint32_t) (max44009_data_to_lux(high,low) * 1000); 119 | return res; 120 | } 121 | 122 | -------------------------------------------------------------------------------- /applications/10_sensored_bldc/main.cpp: -------------------------------------------------------------------------------- 1 | /** @file main.c 2 | * 3 | * main entry for the application nRF52_dongle 4 | * 5 | * @author Wassim FILALI 6 | * 7 | * @compiler arm gcc 8 | * 9 | * 10 | * $Date: 01.06.2018 adding doxy header this file existed since the repo creation 11 | * 12 | */ 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | extern "C" 19 | { 20 | #include "sdk_config.h" 21 | 22 | //#include "nrf.h" 23 | //#include "nrf_error.h" 24 | #include "nrf_delay.h" 25 | #include "nrf_gpio.h" 26 | #include "boards.h" 27 | #include "app_util.h" 28 | 29 | #include "bsp.h" 30 | 31 | 32 | //for the log 33 | #include "nrf_log.h" 34 | #include "nrf_log_ctrl.h" 35 | #include "nrf_log_default_backends.h" 36 | 37 | // --------------------- inputs from sdk_config --------------------- 38 | // ---> TWI0_ENABLED ---> TWI1_ENABLED 39 | #include "uicr_user_defines.h" 40 | //drivers 41 | //apps 42 | #include "clocks.h" 43 | #include "utils.h" 44 | } 45 | 46 | #include "strmap.hpp" 47 | #include "usb_print.hpp" 48 | #include "bldc.hpp" 49 | 50 | 51 | 52 | 53 | #define PWM_INSTANCE 0 54 | #define GPIO_M_P1 NRF_GPIO_PIN_MAP(0,10) 55 | #define GPIO_M_P2 NRF_GPIO_PIN_MAP(0,9) 56 | #define GPIO_M_P3 NRF_GPIO_PIN_MAP(1,0) 57 | #define GPIO_M_EN NRF_GPIO_PIN_MAP(0,24) 58 | 59 | bldc_c motor(PWM_INSTANCE,GPIO_M_P1,GPIO_M_P2,GPIO_M_P3); 60 | 61 | void app_usb_rx_handler(const char*msg,uint8_t size); 62 | 63 | usb_c usb(app_usb_rx_handler); 64 | 65 | uint8_t id = get_this_node_id(); 66 | std::string motor_topic(std::to_string(id) + "/motor_ctl"); 67 | 68 | void app_usb_rx_handler(const char*msg,uint8_t size) 69 | { 70 | strmap_c params(msg,size); 71 | if(params.topic.compare(motor_topic) == 0) 72 | { 73 | if(params.has("norm")) 74 | { 75 | float norm = std::stof(params["norm"]); 76 | motor.set_norm(norm); 77 | } 78 | if(params.has("target")) 79 | { 80 | float target = std::stof(params["target"]); 81 | motor.set_target(target); 82 | } 83 | if(params.has("speed")) 84 | { 85 | float speed = std::stof(params["speed"]); 86 | motor.set_speed(speed); 87 | } 88 | usb.printf("%u/motor>norm:%0.2f;target:%0.2f;speed:%0.2f;\r\n", 89 | id, 90 | motor.norm, 91 | motor.absolute_target, 92 | motor.rot_per_sec); 93 | } 94 | } 95 | 96 | 97 | /** 98 | * @brief application rtc event which is a configurable period delay 99 | * through the uicr config "sleep" in the nodes databse 100 | * 101 | */ 102 | void app_rtc_handler() 103 | { 104 | static uint32_t alive_count = 0; 105 | led2_green_on(); 106 | usb.printf("%u/alive>%lu\r\n",id,alive_count++); 107 | led2_green_off(); 108 | } 109 | 110 | int main(void) 111 | { 112 | //--------------------- Important UICR settings --------------------- 113 | //UICR.NFCPINS = 0xFFFFFFFE - Disabled 114 | //UICR.REGOUT0 = 0xFFFFFFFD - 3.3 V 115 | 116 | clocks_start(); 117 | 118 | bsp_board_init(BSP_INIT_LEDS); 119 | 120 | blink_red(1000,200); 121 | blink_green(1000,200); 122 | blink_blue(1000,200); 123 | 124 | nrf_gpio_cfg_output(GPIO_M_EN); 125 | nrf_gpio_pin_set(GPIO_M_EN); 126 | 127 | // ------------------------- Start Init ------------------------- 128 | usb.printf("%u/reset>1\r\n");//will be lost if port is closed 129 | rtc_config(app_rtc_handler); 130 | 131 | 132 | // ------------------------- Start Events ------------------------- 133 | uint32_t count = 0; 134 | while(true) 135 | { 136 | usb.loop(); 137 | nrf_delay_us(1000); 138 | if((count % 500) == 0) 139 | { 140 | usb.printf("%u/motor>absolute_steps:%0.3f\r\n",id,motor.absolute_steps); 141 | } 142 | count++; 143 | } 144 | } 145 | /*lint -restore */ 146 | -------------------------------------------------------------------------------- /applications/08_usb_dongle/openthread_nrf52840.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | -------------------------------------------------------------------------------- /applications/09_usb_dongle_cpp/openthread_nrf52840.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | -------------------------------------------------------------------------------- /applications/10_sensored_bldc/openthread_nrf52840.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x100000 9 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | -------------------------------------------------------------------------------- /applications/08_usb_dongle/openthread_nrf52840_bootloader.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xdf000 9 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3fff8 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | -------------------------------------------------------------------------------- /applications/10_sensored_bldc/openthread_nrf52840_bootloader.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xdf000 9 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3fff8 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | -------------------------------------------------------------------------------- /applications/09_usb_dongle_cpp/openthread_nrf52840_bootloader.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | 3 | SEARCH_DIR(.) 4 | GROUP(-lgcc -lc -lnosys) 5 | 6 | MEMORY 7 | { 8 | FLASH (rx) : ORIGIN = 0x1000, LENGTH = 0xdf000 9 | RAM (rwx) : ORIGIN = 0x20000008, LENGTH = 0x3fff8 10 | } 11 | 12 | FLASH_PAGE_SIZE = 4096; 13 | FLASH_DATA_PAGES_USED = 4; 14 | 15 | SECTIONS 16 | { 17 | . = ALIGN(4); 18 | .svc_data : 19 | { 20 | PROVIDE(__start_svc_data = .); 21 | KEEP(*(.svc_data)) 22 | PROVIDE(__stop_svc_data = .); 23 | } > RAM 24 | .fs_data : 25 | { 26 | PROVIDE(__start_fs_data = .); 27 | KEEP(*(.fs_data)) 28 | PROVIDE(__stop_fs_data = .); 29 | } > RAM 30 | .log_dynamic_data : 31 | { 32 | PROVIDE(__start_log_dynamic_data = .); 33 | KEEP(*(SORT(.log_dynamic_data*))) 34 | PROVIDE(__stop_log_dynamic_data = .); 35 | } > RAM 36 | .log_filter_data : 37 | { 38 | PROVIDE(__start_log_filter_data = .); 39 | KEEP(*(SORT(.log_filter_data*))) 40 | PROVIDE(__stop_log_filter_data = .); 41 | } > RAM 42 | .cli_sorted_cmd_ptrs : 43 | { 44 | PROVIDE(__start_cli_sorted_cmd_ptrs = .); 45 | KEEP(*(.cli_sorted_cmd_ptrs)) 46 | PROVIDE(__stop_cli_sorted_cmd_ptrs = .); 47 | } > RAM 48 | } INSERT AFTER .data; 49 | 50 | SECTIONS 51 | { 52 | .pwr_mgmt_data : 53 | { 54 | PROVIDE(__start_pwr_mgmt_data = .); 55 | KEEP(*(SORT(.pwr_mgmt_data*))) 56 | PROVIDE(__stop_pwr_mgmt_data = .); 57 | } > FLASH 58 | .log_const_data : 59 | { 60 | PROVIDE(__start_log_const_data = .); 61 | KEEP(*(SORT(.log_const_data*))) 62 | PROVIDE(__stop_log_const_data = .); 63 | } > FLASH 64 | .log_backends : 65 | { 66 | PROVIDE(__start_log_backends = .); 67 | KEEP(*(SORT(.log_backends*))) 68 | PROVIDE(__stop_log_backends = .); 69 | } > FLASH 70 | .nrf_balloc : 71 | { 72 | PROVIDE(__start_nrf_balloc = .); 73 | KEEP(*(.nrf_balloc)) 74 | PROVIDE(__stop_nrf_balloc = .); 75 | } > FLASH 76 | .nrf_queue : 77 | { 78 | PROVIDE(__start_nrf_queue = .); 79 | KEEP(*(.nrf_queue)) 80 | PROVIDE(__stop_nrf_queue = .); 81 | } > FLASH 82 | .cli_command : 83 | { 84 | PROVIDE(__start_cli_command = .); 85 | KEEP(*(.cli_command)) 86 | PROVIDE(__stop_cli_command = .); 87 | } > FLASH 88 | .sdh_stack_observers : 89 | { 90 | PROVIDE(__start_sdh_stack_observers = .); 91 | KEEP(*(SORT(.sdh_stack_observers*))) 92 | PROVIDE(__stop_sdh_stack_observers = .); 93 | } > FLASH 94 | .sdh_req_observers : 95 | { 96 | PROVIDE(__start_sdh_req_observers = .); 97 | KEEP(*(SORT(.sdh_req_observers*))) 98 | PROVIDE(__stop_sdh_req_observers = .); 99 | } > FLASH 100 | .sdh_state_observers : 101 | { 102 | PROVIDE(__start_sdh_state_observers = .); 103 | KEEP(*(SORT(.sdh_state_observers*))) 104 | PROVIDE(__stop_sdh_state_observers = .); 105 | } > FLASH 106 | .sdh_ant_observers : 107 | { 108 | PROVIDE(__start_sdh_ant_observers = .); 109 | KEEP(*(SORT(.sdh_ant_observers*))) 110 | PROVIDE(__stop_sdh_ant_observers = .); 111 | } > FLASH 112 | .sdh_ble_observers : 113 | { 114 | PROVIDE(__start_sdh_ble_observers = .); 115 | KEEP(*(SORT(.sdh_ble_observers*))) 116 | PROVIDE(__stop_sdh_ble_observers = .); 117 | } > FLASH 118 | .sdh_soc_observers : 119 | { 120 | PROVIDE(__start_sdh_soc_observers = .); 121 | KEEP(*(SORT(.sdh_soc_observers*))) 122 | PROVIDE(__stop_sdh_soc_observers = .); 123 | } > FLASH 124 | .crypto_data : 125 | { 126 | PROVIDE(__start_crypto_data = .); 127 | KEEP(*(SORT(.crypto_data*))) 128 | PROVIDE(__stop_crypto_data = .); 129 | } > FLASH 130 | } INSERT AFTER .text 131 | 132 | SECTIONS 133 | { 134 | __stop_ot_flash_data = (ORIGIN(FLASH) + LENGTH(FLASH)); 135 | __start_ot_flash_data = (__stop_ot_flash_data - (FLASH_PAGE_SIZE * FLASH_DATA_PAGES_USED)); 136 | 137 | /* Assure that code does not overlap flash data area.*/ 138 | ASSERT((__start_ot_flash_data >= __etext + SIZEOF(.data)), "Error: Code overlaps flash data area.") 139 | } 140 | 141 | INCLUDE "nrf_common.ld" 142 | --------------------------------------------------------------------------------