summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules10
m---------bt-server0
m---------sensor/DHTesp0
-rw-r--r--sensor/Makefile10
-rw-r--r--sensor/README.rst.txt37
m---------sensor/esp8266-oled-ssd13060
-rw-r--r--sensor/patchedBLE/README.md (renamed from README.md)0
-rw-r--r--sensor/patchedBLE/examples/BLE_client/BLE_client.ino (renamed from examples/BLE_client/BLE_client.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_iBeacon/BLE_iBeacon.ino (renamed from examples/BLE_iBeacon/BLE_iBeacon.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino (renamed from examples/BLE_notify/BLE_notify.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_scan/BLE_scan.ino (renamed from examples/BLE_scan/BLE_scan.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_server/BLE_server.ino (renamed from examples/BLE_server/BLE_server.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_server_multiconnect/BLE_server_multiconnect.ino (renamed from examples/BLE_server_multiconnect/BLE_server_multiconnect.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_uart/BLE_uart.ino (renamed from examples/BLE_uart/BLE_uart.ino)0
-rw-r--r--sensor/patchedBLE/examples/BLE_write/BLE_write.ino (renamed from examples/BLE_write/BLE_write.ino)0
-rw-r--r--sensor/patchedBLE/library.properties (renamed from library.properties)0
-rw-r--r--sensor/patchedBLE/src/BLE2902.cpp (renamed from src/BLE2902.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLE2902.h (renamed from src/BLE2902.h)0
-rw-r--r--sensor/patchedBLE/src/BLE2904.cpp (renamed from src/BLE2904.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLE2904.h (renamed from src/BLE2904.h)0
-rw-r--r--sensor/patchedBLE/src/BLEAddress.cpp (renamed from src/BLEAddress.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEAddress.h (renamed from src/BLEAddress.h)0
-rw-r--r--sensor/patchedBLE/src/BLEAdvertisedDevice.cpp (renamed from src/BLEAdvertisedDevice.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEAdvertisedDevice.h (renamed from src/BLEAdvertisedDevice.h)0
-rw-r--r--sensor/patchedBLE/src/BLEAdvertising.cpp (renamed from src/BLEAdvertising.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEAdvertising.h (renamed from src/BLEAdvertising.h)0
-rw-r--r--sensor/patchedBLE/src/BLEBeacon.cpp (renamed from src/BLEBeacon.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEBeacon.h (renamed from src/BLEBeacon.h)0
-rw-r--r--sensor/patchedBLE/src/BLECharacteristic.cpp (renamed from src/BLECharacteristic.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLECharacteristic.h (renamed from src/BLECharacteristic.h)0
-rw-r--r--sensor/patchedBLE/src/BLECharacteristicMap.cpp (renamed from src/BLECharacteristicMap.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEClient.cpp (renamed from src/BLEClient.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEClient.h (renamed from src/BLEClient.h)0
-rw-r--r--sensor/patchedBLE/src/BLEDescriptor.cpp (renamed from src/BLEDescriptor.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEDescriptor.h (renamed from src/BLEDescriptor.h)0
-rw-r--r--sensor/patchedBLE/src/BLEDescriptorMap.cpp (renamed from src/BLEDescriptorMap.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEDevice.cpp (renamed from src/BLEDevice.cpp)8
-rw-r--r--sensor/patchedBLE/src/BLEDevice.h (renamed from src/BLEDevice.h)1
-rw-r--r--sensor/patchedBLE/src/BLEEddystoneTLM.cpp (renamed from src/BLEEddystoneTLM.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEEddystoneTLM.h (renamed from src/BLEEddystoneTLM.h)0
-rw-r--r--sensor/patchedBLE/src/BLEEddystoneURL.cpp (renamed from src/BLEEddystoneURL.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEEddystoneURL.h (renamed from src/BLEEddystoneURL.h)0
-rw-r--r--sensor/patchedBLE/src/BLEExceptions.cpp (renamed from src/BLEExceptions.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEExceptions.h (renamed from src/BLEExceptions.h)0
-rw-r--r--sensor/patchedBLE/src/BLEHIDDevice.cpp (renamed from src/BLEHIDDevice.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEHIDDevice.h (renamed from src/BLEHIDDevice.h)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteCharacteristic.cpp (renamed from src/BLERemoteCharacteristic.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteCharacteristic.h (renamed from src/BLERemoteCharacteristic.h)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteDescriptor.cpp (renamed from src/BLERemoteDescriptor.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteDescriptor.h (renamed from src/BLERemoteDescriptor.h)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteService.cpp (renamed from src/BLERemoteService.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLERemoteService.h (renamed from src/BLERemoteService.h)0
-rw-r--r--sensor/patchedBLE/src/BLEScan.cpp (renamed from src/BLEScan.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEScan.h (renamed from src/BLEScan.h)0
-rw-r--r--sensor/patchedBLE/src/BLESecurity.cpp (renamed from src/BLESecurity.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLESecurity.h (renamed from src/BLESecurity.h)0
-rw-r--r--sensor/patchedBLE/src/BLEServer.cpp (renamed from src/BLEServer.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEServer.h (renamed from src/BLEServer.h)0
-rw-r--r--sensor/patchedBLE/src/BLEService.cpp (renamed from src/BLEService.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEService.h (renamed from src/BLEService.h)0
-rw-r--r--sensor/patchedBLE/src/BLEServiceMap.cpp (renamed from src/BLEServiceMap.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEUUID.cpp (renamed from src/BLEUUID.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEUUID.h (renamed from src/BLEUUID.h)0
-rw-r--r--sensor/patchedBLE/src/BLEUtils.cpp (renamed from src/BLEUtils.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEUtils.h (renamed from src/BLEUtils.h)0
-rw-r--r--sensor/patchedBLE/src/BLEValue.cpp (renamed from src/BLEValue.cpp)0
-rw-r--r--sensor/patchedBLE/src/BLEValue.h (renamed from src/BLEValue.h)0
-rw-r--r--sensor/patchedBLE/src/FreeRTOS.cpp (renamed from src/FreeRTOS.cpp)0
-rw-r--r--sensor/patchedBLE/src/FreeRTOS.h (renamed from src/FreeRTOS.h)0
-rw-r--r--sensor/patchedBLE/src/GeneralUtils.cpp (renamed from src/GeneralUtils.cpp)0
-rw-r--r--sensor/patchedBLE/src/GeneralUtils.h (renamed from src/GeneralUtils.h)0
-rw-r--r--sensor/patchedBLE/src/HIDKeyboardTypes.h (renamed from src/HIDKeyboardTypes.h)0
-rw-r--r--sensor/patchedBLE/src/HIDTypes.h (renamed from src/HIDTypes.h)0
-rw-r--r--sensor/thermostat.ino194
-rw-r--r--trasmitter/.gitignore3
-rw-r--r--trasmitter/Makefile10
-rw-r--r--trasmitter/README.rst.txt42
-rw-r--r--trasmitter/arduino/Makefile19
-rw-r--r--trasmitter/arduino/sender.ino93
-rw-r--r--trasmitter/sender-chip.c146
-rw-r--r--trasmitter/sender-chip.pl91
81 files changed, 664 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..3838dc9
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,10 @@
+[submodule "DHTesp"]
+ path = sensor/DHTesp
+ url = https://github.com/beegee-tokyo/DHTesp
+[submodule "esp8266-oled-ssd1306"]
+ path = sensor/esp8266-oled-ssd1306
+ url = https://github.com/ThingPulse/esp8266-oled-ssd1306
+[submodule "bt-server"]
+ path = bt-server
+ url = git@luxion:gobbledegook
+ branch = bt-temp-print
diff --git a/bt-server b/bt-server
new file mode 160000
+Subproject 39ed3c1e6b35bad02618d958b425cf0b96fd7b1
diff --git a/sensor/DHTesp b/sensor/DHTesp
new file mode 160000
+Subproject 1feec8159cbf9224cdb46f45f57306bcab30c81
diff --git a/sensor/Makefile b/sensor/Makefile
new file mode 100644
index 0000000..085e162
--- /dev/null
+++ b/sensor/Makefile
@@ -0,0 +1,10 @@
+SKETCH = thermostat.ino
+CUSTOM_LIBS = DHTesp esp8266-oled-ssd1306 patchedBLE
+
+UPLOAD_PORT = /dev/ttyUSB0
+BOARD = lolin32
+
+ESP_ROOT = $(HOME)/Arduino/hardware/espressif/esp32/
+CHIP = esp32
+
+include $(HOME)/src/makeEspArduino/makeEspArduino.mk
diff --git a/sensor/README.rst.txt b/sensor/README.rst.txt
new file mode 100644
index 0000000..1ca8b47
--- /dev/null
+++ b/sensor/README.rst.txt
@@ -0,0 +1,37 @@
+Some links:
+
+* links to some ESP32 libraries
+ https://www.arduinolibraries.info/architectures/esp32
+* the OLED library https://github.com/ThingPulse/esp8266-oled-ssd1306
+* vague guide to the OLED library
+ https://diyprojects.io/using-i2c-128x64-0-96-ssd1306-oled-display-arduino/
+* the sensor library https://github.com/beegee-tokyo/DHTesp
+
+* Ultra Low Power mode for ESP32:
+
+ - not Arduino-style
+ https://github.com/espressif/esp-idf/blob/master/examples/system/deep_sleep/main/deep_sleep_example_main.c
+ - Arduino-style
+ https://github.com/espressif/arduino-esp32/blob/master/libraries/ESP32/examples/DeepSleep/TimerWakeUp/TimerWakeUp.ino
+
+* BLE examples
+ http://www.iotsharing.com/2017/07/how-to-use-ble-in-arduino-esp32.html
+ https://github.com/nkolban/ESP32_BLE_Arduino/blob/6bad7b42a96f0aa493323ef4821a8efb0e8815f2/examples/BLE_notify/BLE_notify.ino
+
+ maybe we want to have the esp32 *write* to the main thermostat?
+
+ - deep sleep
+ - read temperature
+ - BLE passive scan for thermostat
+ - connect
+ - write id + values to a property
+ - disconnect
+ - repeat
+
+ example Python server:
+ https://github.com/RadiusNetworks/bluez/blob/master/test/example-gatt-server
+
+ C++ library: https://github.com/nettlep/gobbledegook
+
+NOTE: the ``patchedBLE`` subtree comes from
+https://github.com/nkolban/ESP32_BLE_Arduino.git
diff --git a/sensor/esp8266-oled-ssd1306 b/sensor/esp8266-oled-ssd1306
new file mode 160000
+Subproject cb294b0d5e938864ba935a8e917082e5496399c
diff --git a/README.md b/sensor/patchedBLE/README.md
index e80fbe0..e80fbe0 100644
--- a/README.md
+++ b/sensor/patchedBLE/README.md
diff --git a/examples/BLE_client/BLE_client.ino b/sensor/patchedBLE/examples/BLE_client/BLE_client.ino
index 4c58299..4c58299 100644
--- a/examples/BLE_client/BLE_client.ino
+++ b/sensor/patchedBLE/examples/BLE_client/BLE_client.ino
diff --git a/examples/BLE_iBeacon/BLE_iBeacon.ino b/sensor/patchedBLE/examples/BLE_iBeacon/BLE_iBeacon.ino
index e43174d..e43174d 100644
--- a/examples/BLE_iBeacon/BLE_iBeacon.ino
+++ b/sensor/patchedBLE/examples/BLE_iBeacon/BLE_iBeacon.ino
diff --git a/examples/BLE_notify/BLE_notify.ino b/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino
index 42b9e72..42b9e72 100644
--- a/examples/BLE_notify/BLE_notify.ino
+++ b/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino
diff --git a/examples/BLE_scan/BLE_scan.ino b/sensor/patchedBLE/examples/BLE_scan/BLE_scan.ino
index 094f793..094f793 100644
--- a/examples/BLE_scan/BLE_scan.ino
+++ b/sensor/patchedBLE/examples/BLE_scan/BLE_scan.ino
diff --git a/examples/BLE_server/BLE_server.ino b/sensor/patchedBLE/examples/BLE_server/BLE_server.ino
index 3f9176a..3f9176a 100644
--- a/examples/BLE_server/BLE_server.ino
+++ b/sensor/patchedBLE/examples/BLE_server/BLE_server.ino
diff --git a/examples/BLE_server_multiconnect/BLE_server_multiconnect.ino b/sensor/patchedBLE/examples/BLE_server_multiconnect/BLE_server_multiconnect.ino
index 90704ef..90704ef 100644
--- a/examples/BLE_server_multiconnect/BLE_server_multiconnect.ino
+++ b/sensor/patchedBLE/examples/BLE_server_multiconnect/BLE_server_multiconnect.ino
diff --git a/examples/BLE_uart/BLE_uart.ino b/sensor/patchedBLE/examples/BLE_uart/BLE_uart.ino
index 35b570b..35b570b 100644
--- a/examples/BLE_uart/BLE_uart.ino
+++ b/sensor/patchedBLE/examples/BLE_uart/BLE_uart.ino
diff --git a/examples/BLE_write/BLE_write.ino b/sensor/patchedBLE/examples/BLE_write/BLE_write.ino
index 24a0cd2..24a0cd2 100644
--- a/examples/BLE_write/BLE_write.ino
+++ b/sensor/patchedBLE/examples/BLE_write/BLE_write.ino
diff --git a/library.properties b/sensor/patchedBLE/library.properties
index 8c2a019..8c2a019 100644
--- a/library.properties
+++ b/sensor/patchedBLE/library.properties
diff --git a/src/BLE2902.cpp b/sensor/patchedBLE/src/BLE2902.cpp
index 23d9c77..23d9c77 100644
--- a/src/BLE2902.cpp
+++ b/sensor/patchedBLE/src/BLE2902.cpp
diff --git a/src/BLE2902.h b/sensor/patchedBLE/src/BLE2902.h
index 397360a..397360a 100644
--- a/src/BLE2902.h
+++ b/sensor/patchedBLE/src/BLE2902.h
diff --git a/src/BLE2904.cpp b/sensor/patchedBLE/src/BLE2904.cpp
index 02252a1..02252a1 100644
--- a/src/BLE2904.cpp
+++ b/sensor/patchedBLE/src/BLE2904.cpp
diff --git a/src/BLE2904.h b/sensor/patchedBLE/src/BLE2904.h
index cb337e2..cb337e2 100644
--- a/src/BLE2904.h
+++ b/sensor/patchedBLE/src/BLE2904.h
diff --git a/src/BLEAddress.cpp b/sensor/patchedBLE/src/BLEAddress.cpp
index d688334..d688334 100644
--- a/src/BLEAddress.cpp
+++ b/sensor/patchedBLE/src/BLEAddress.cpp
diff --git a/src/BLEAddress.h b/sensor/patchedBLE/src/BLEAddress.h
index 7eff4da..7eff4da 100644
--- a/src/BLEAddress.h
+++ b/sensor/patchedBLE/src/BLEAddress.h
diff --git a/src/BLEAdvertisedDevice.cpp b/sensor/patchedBLE/src/BLEAdvertisedDevice.cpp
index 3f55e8c..3f55e8c 100644
--- a/src/BLEAdvertisedDevice.cpp
+++ b/sensor/patchedBLE/src/BLEAdvertisedDevice.cpp
diff --git a/src/BLEAdvertisedDevice.h b/sensor/patchedBLE/src/BLEAdvertisedDevice.h
index aec8374..aec8374 100644
--- a/src/BLEAdvertisedDevice.h
+++ b/sensor/patchedBLE/src/BLEAdvertisedDevice.h
diff --git a/src/BLEAdvertising.cpp b/sensor/patchedBLE/src/BLEAdvertising.cpp
index 230d77c..230d77c 100644
--- a/src/BLEAdvertising.cpp
+++ b/sensor/patchedBLE/src/BLEAdvertising.cpp
diff --git a/src/BLEAdvertising.h b/sensor/patchedBLE/src/BLEAdvertising.h
index 3128b50..3128b50 100644
--- a/src/BLEAdvertising.h
+++ b/sensor/patchedBLE/src/BLEAdvertising.h
diff --git a/src/BLEBeacon.cpp b/sensor/patchedBLE/src/BLEBeacon.cpp
index 68f8d8e..68f8d8e 100644
--- a/src/BLEBeacon.cpp
+++ b/sensor/patchedBLE/src/BLEBeacon.cpp
diff --git a/src/BLEBeacon.h b/sensor/patchedBLE/src/BLEBeacon.h
index 277bd67..277bd67 100644
--- a/src/BLEBeacon.h
+++ b/sensor/patchedBLE/src/BLEBeacon.h
diff --git a/src/BLECharacteristic.cpp b/sensor/patchedBLE/src/BLECharacteristic.cpp
index e340287..e340287 100644
--- a/src/BLECharacteristic.cpp
+++ b/sensor/patchedBLE/src/BLECharacteristic.cpp
diff --git a/src/BLECharacteristic.h b/sensor/patchedBLE/src/BLECharacteristic.h
index 5eb1e8d..5eb1e8d 100644
--- a/src/BLECharacteristic.h
+++ b/sensor/patchedBLE/src/BLECharacteristic.h
diff --git a/src/BLECharacteristicMap.cpp b/sensor/patchedBLE/src/BLECharacteristicMap.cpp
index d73aae9..d73aae9 100644
--- a/src/BLECharacteristicMap.cpp
+++ b/sensor/patchedBLE/src/BLECharacteristicMap.cpp
diff --git a/src/BLEClient.cpp b/sensor/patchedBLE/src/BLEClient.cpp
index 0e552ec..0e552ec 100644
--- a/src/BLEClient.cpp
+++ b/sensor/patchedBLE/src/BLEClient.cpp
diff --git a/src/BLEClient.h b/sensor/patchedBLE/src/BLEClient.h
index 1b8144d..1b8144d 100644
--- a/src/BLEClient.h
+++ b/sensor/patchedBLE/src/BLEClient.h
diff --git a/src/BLEDescriptor.cpp b/sensor/patchedBLE/src/BLEDescriptor.cpp
index ba5753d..ba5753d 100644
--- a/src/BLEDescriptor.cpp
+++ b/sensor/patchedBLE/src/BLEDescriptor.cpp
diff --git a/src/BLEDescriptor.h b/sensor/patchedBLE/src/BLEDescriptor.h
index 03cc579..03cc579 100644
--- a/src/BLEDescriptor.h
+++ b/sensor/patchedBLE/src/BLEDescriptor.h
diff --git a/src/BLEDescriptorMap.cpp b/sensor/patchedBLE/src/BLEDescriptorMap.cpp
index 6b84583..6b84583 100644
--- a/src/BLEDescriptorMap.cpp
+++ b/sensor/patchedBLE/src/BLEDescriptorMap.cpp
diff --git a/src/BLEDevice.cpp b/sensor/patchedBLE/src/BLEDevice.cpp
index cb2db41..4dbbc6e 100644
--- a/src/BLEDevice.cpp
+++ b/sensor/patchedBLE/src/BLEDevice.cpp
@@ -435,6 +435,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
vTaskDelay(200 / portTICK_PERIOD_MS); // Delay for 200 msecs as a workaround to an apparent Arduino environment issue.
} // init
+void BLEDevice::uninit() {
+ if (initialized) {
+ initialized = false;
+ esp_bluedroid_disable();
+ esp_bt_controller_disable();
+ esp_bt_controller_deinit();
+ }
+}
/**
* @brief Set the transmission power.
diff --git a/src/BLEDevice.h b/sensor/patchedBLE/src/BLEDevice.h
index e9cd40a..cb4fc17 100644
--- a/src/BLEDevice.h
+++ b/sensor/patchedBLE/src/BLEDevice.h
@@ -37,6 +37,7 @@ public:
static BLEScan* getScan(); // Get the scan object
static std::string getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID); // Get the value of a characteristic of a service on a server.
static void init(std::string deviceName); // Initialize the local BLE environment.
+ static void uninit();
static void setPower(esp_power_level_t powerLevel); // Set our power level.
static void setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value); // Set the value of a characteristic on a service on a server.
static std::string toString(); // Return a string representation of our device.
diff --git a/src/BLEEddystoneTLM.cpp b/sensor/patchedBLE/src/BLEEddystoneTLM.cpp
index a92bcdb..a92bcdb 100644
--- a/src/BLEEddystoneTLM.cpp
+++ b/sensor/patchedBLE/src/BLEEddystoneTLM.cpp
diff --git a/src/BLEEddystoneTLM.h b/sensor/patchedBLE/src/BLEEddystoneTLM.h
index a93e224..a93e224 100644
--- a/src/BLEEddystoneTLM.h
+++ b/sensor/patchedBLE/src/BLEEddystoneTLM.h
diff --git a/src/BLEEddystoneURL.cpp b/sensor/patchedBLE/src/BLEEddystoneURL.cpp
index af3b674..af3b674 100644
--- a/src/BLEEddystoneURL.cpp
+++ b/sensor/patchedBLE/src/BLEEddystoneURL.cpp
diff --git a/src/BLEEddystoneURL.h b/sensor/patchedBLE/src/BLEEddystoneURL.h
index 0b538c0..0b538c0 100644
--- a/src/BLEEddystoneURL.h
+++ b/sensor/patchedBLE/src/BLEEddystoneURL.h
diff --git a/src/BLEExceptions.cpp b/sensor/patchedBLE/src/BLEExceptions.cpp
index b6adfd8..b6adfd8 100644
--- a/src/BLEExceptions.cpp
+++ b/sensor/patchedBLE/src/BLEExceptions.cpp
diff --git a/src/BLEExceptions.h b/sensor/patchedBLE/src/BLEExceptions.h
index ea9db85..ea9db85 100644
--- a/src/BLEExceptions.h
+++ b/sensor/patchedBLE/src/BLEExceptions.h
diff --git a/src/BLEHIDDevice.cpp b/sensor/patchedBLE/src/BLEHIDDevice.cpp
index 69e18be..69e18be 100644
--- a/src/BLEHIDDevice.cpp
+++ b/sensor/patchedBLE/src/BLEHIDDevice.cpp
diff --git a/src/BLEHIDDevice.h b/sensor/patchedBLE/src/BLEHIDDevice.h
index 33e6b46..33e6b46 100644
--- a/src/BLEHIDDevice.h
+++ b/sensor/patchedBLE/src/BLEHIDDevice.h
diff --git a/src/BLERemoteCharacteristic.cpp b/sensor/patchedBLE/src/BLERemoteCharacteristic.cpp
index b6d36d8..b6d36d8 100644
--- a/src/BLERemoteCharacteristic.cpp
+++ b/sensor/patchedBLE/src/BLERemoteCharacteristic.cpp
diff --git a/src/BLERemoteCharacteristic.h b/sensor/patchedBLE/src/BLERemoteCharacteristic.h
index fbcafe8..fbcafe8 100644
--- a/src/BLERemoteCharacteristic.h
+++ b/sensor/patchedBLE/src/BLERemoteCharacteristic.h
diff --git a/src/BLERemoteDescriptor.cpp b/sensor/patchedBLE/src/BLERemoteDescriptor.cpp
index 96a8a57..96a8a57 100644
--- a/src/BLERemoteDescriptor.cpp
+++ b/sensor/patchedBLE/src/BLERemoteDescriptor.cpp
diff --git a/src/BLERemoteDescriptor.h b/sensor/patchedBLE/src/BLERemoteDescriptor.h
index 7bbc48f..7bbc48f 100644
--- a/src/BLERemoteDescriptor.h
+++ b/sensor/patchedBLE/src/BLERemoteDescriptor.h
diff --git a/src/BLERemoteService.cpp b/sensor/patchedBLE/src/BLERemoteService.cpp
index c2b7d34..c2b7d34 100644
--- a/src/BLERemoteService.cpp
+++ b/sensor/patchedBLE/src/BLERemoteService.cpp
diff --git a/src/BLERemoteService.h b/sensor/patchedBLE/src/BLERemoteService.h
index 2ab8673..2ab8673 100644
--- a/src/BLERemoteService.h
+++ b/sensor/patchedBLE/src/BLERemoteService.h
diff --git a/src/BLEScan.cpp b/sensor/patchedBLE/src/BLEScan.cpp
index d851a47..d851a47 100644
--- a/src/BLEScan.cpp
+++ b/sensor/patchedBLE/src/BLEScan.cpp
diff --git a/src/BLEScan.h b/sensor/patchedBLE/src/BLEScan.h
index 2f71a72..2f71a72 100644
--- a/src/BLEScan.h
+++ b/sensor/patchedBLE/src/BLEScan.h
diff --git a/src/BLESecurity.cpp b/sensor/patchedBLE/src/BLESecurity.cpp
index 921f542..921f542 100644
--- a/src/BLESecurity.cpp
+++ b/sensor/patchedBLE/src/BLESecurity.cpp
diff --git a/src/BLESecurity.h b/sensor/patchedBLE/src/BLESecurity.h
index 48d09d2..48d09d2 100644
--- a/src/BLESecurity.h
+++ b/sensor/patchedBLE/src/BLESecurity.h
diff --git a/src/BLEServer.cpp b/sensor/patchedBLE/src/BLEServer.cpp
index 6a780aa..6a780aa 100644
--- a/src/BLEServer.cpp
+++ b/sensor/patchedBLE/src/BLEServer.cpp
diff --git a/src/BLEServer.h b/sensor/patchedBLE/src/BLEServer.h
index d39d8bf..d39d8bf 100644
--- a/src/BLEServer.h
+++ b/sensor/patchedBLE/src/BLEServer.h
diff --git a/src/BLEService.cpp b/sensor/patchedBLE/src/BLEService.cpp
index 3034cf1..3034cf1 100644
--- a/src/BLEService.cpp
+++ b/sensor/patchedBLE/src/BLEService.cpp
diff --git a/src/BLEService.h b/sensor/patchedBLE/src/BLEService.h
index b42d57f..b42d57f 100644
--- a/src/BLEService.h
+++ b/sensor/patchedBLE/src/BLEService.h
diff --git a/src/BLEServiceMap.cpp b/sensor/patchedBLE/src/BLEServiceMap.cpp
index cf4f75f..cf4f75f 100644
--- a/src/BLEServiceMap.cpp
+++ b/sensor/patchedBLE/src/BLEServiceMap.cpp
diff --git a/src/BLEUUID.cpp b/sensor/patchedBLE/src/BLEUUID.cpp
index 4ddf8fc..4ddf8fc 100644
--- a/src/BLEUUID.cpp
+++ b/sensor/patchedBLE/src/BLEUUID.cpp
diff --git a/src/BLEUUID.h b/sensor/patchedBLE/src/BLEUUID.h
index 700739b..700739b 100644
--- a/src/BLEUUID.h
+++ b/sensor/patchedBLE/src/BLEUUID.h
diff --git a/src/BLEUtils.cpp b/sensor/patchedBLE/src/BLEUtils.cpp
index 5cd55f9..5cd55f9 100644
--- a/src/BLEUtils.cpp
+++ b/sensor/patchedBLE/src/BLEUtils.cpp
diff --git a/src/BLEUtils.h b/sensor/patchedBLE/src/BLEUtils.h
index 7981691..7981691 100644
--- a/src/BLEUtils.h
+++ b/sensor/patchedBLE/src/BLEUtils.h
diff --git a/src/BLEValue.cpp b/sensor/patchedBLE/src/BLEValue.cpp
index ec1e61f..ec1e61f 100644
--- a/src/BLEValue.cpp
+++ b/sensor/patchedBLE/src/BLEValue.cpp
diff --git a/src/BLEValue.h b/sensor/patchedBLE/src/BLEValue.h
index 5df904c..5df904c 100644
--- a/src/BLEValue.h
+++ b/sensor/patchedBLE/src/BLEValue.h
diff --git a/src/FreeRTOS.cpp b/sensor/patchedBLE/src/FreeRTOS.cpp
index 1f12c88..1f12c88 100644
--- a/src/FreeRTOS.cpp
+++ b/sensor/patchedBLE/src/FreeRTOS.cpp
diff --git a/src/FreeRTOS.h b/sensor/patchedBLE/src/FreeRTOS.h
index b861c87..b861c87 100644
--- a/src/FreeRTOS.h
+++ b/sensor/patchedBLE/src/FreeRTOS.h
diff --git a/src/GeneralUtils.cpp b/sensor/patchedBLE/src/GeneralUtils.cpp
index 019c81b..019c81b 100644
--- a/src/GeneralUtils.cpp
+++ b/sensor/patchedBLE/src/GeneralUtils.cpp
diff --git a/src/GeneralUtils.h b/sensor/patchedBLE/src/GeneralUtils.h
index 8eecbd4..8eecbd4 100644
--- a/src/GeneralUtils.h
+++ b/sensor/patchedBLE/src/GeneralUtils.h
diff --git a/src/HIDKeyboardTypes.h b/sensor/patchedBLE/src/HIDKeyboardTypes.h
index 4e221d5..4e221d5 100644
--- a/src/HIDKeyboardTypes.h
+++ b/sensor/patchedBLE/src/HIDKeyboardTypes.h
diff --git a/src/HIDTypes.h b/sensor/patchedBLE/src/HIDTypes.h
index 64850ef..64850ef 100644
--- a/src/HIDTypes.h
+++ b/sensor/patchedBLE/src/HIDTypes.h
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino
new file mode 100644
index 0000000..23bc610
--- /dev/null
+++ b/sensor/thermostat.ino
@@ -0,0 +1,194 @@
+#include <string>
+#include <Wire.h>
+#include "SSD1306.h"
+#include "DHTesp.h"
+#include <esp_bt.h>
+#include "BLEDevice.h"
+#include "Ticker.h"
+
+static BLEUUID thermo_service_uuid("11111111-2222-3333-4444-000000000000");
+static BLEUUID thermo_temp_uuid("11111111-2222-3333-4444-000000000001");
+static BLEUUID thermo_time_uuid("11111111-2222-3333-4444-000000000002");
+
+#define NO_SERVER_SLEEP_TIME 60
+#define ON_ERROR_SLEEP_TIME 30
+#define WATCHDOG_SECONDS 30
+/* Conversion factor for micro seconds to seconds */
+#define uS_TO_S_FACTOR 1000000
+
+#define BLE_POWER ESP_PWR_LVL_P7
+// #define BLE_POWER ESP_PWR_LVL_N14
+
+SSD1306 display(0x3c, 5, 4);
+DHTesp dht;
+
+void show(String x) {
+ display.clear();
+ display.drawString(0,0,x);
+ display.display();
+}
+
+class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
+ public:
+ BLEAddress* pServerAddress;
+
+ MyAdvertisedDeviceCallbacks() :
+ BLEAdvertisedDeviceCallbacks(),
+ pServerAddress(0)
+ {}
+
+ ~MyAdvertisedDeviceCallbacks() { if (pServerAddress) delete pServerAddress; }
+
+ void onResult(BLEAdvertisedDevice advertisedDevice) {
+ // We have found a device, let us now see if it contains the service we are looking for.
+ if (advertisedDevice.haveName() && advertisedDevice.getName() == "termostore") {
+ advertisedDevice.getScan()->stop();
+
+ pServerAddress = new BLEAddress(advertisedDevice.getAddress());
+
+ } // Found our server
+ } // onResult
+}; // MyAdvertisedDeviceCallbacks
+
+void enable_sensor(bool enable) {
+ pinMode(12,OUTPUT);
+ digitalWrite(12,enable ? HIGH : LOW);
+ delay(500);
+}
+
+bool read_sensor(float* humidity, float* temperature) {
+ dht.setup(13,DHTesp::DHT11);
+
+ int tries=0;bool ret=false;
+ while (!ret && ++tries<10) {
+ delay(dht.getMinimumSamplingPeriod());
+ *humidity = dht.getHumidity();
+ *temperature = dht.getTemperature();
+
+ String data = "";
+ data += *humidity;
+ data += " ";
+ data += *temperature;
+ data += " ";
+ data += dht.getStatusString();
+ show(data);
+
+ if (dht.getStatus() != DHTesp::ERROR_TIMEOUT) ret = true;
+ }
+ return ret;
+}
+
+uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) {
+ BLEClient* pClient = BLEDevice::createClient();
+ show("Sc");
+ bool ok = pClient->connect(*pAddress);
+ if (!ok) {
+ show("connect fail");
+ return ON_ERROR_SLEEP_TIME;
+ }
+ String status = "SC";
+ status += pClient->getPeerAddress().toString().c_str();
+ show(status);
+ try {
+ BLERemoteService* pThermoService = pClient->getService(thermo_service_uuid);
+ if (!pThermoService) {
+ show("NO SERVICE");
+ return 60;
+ }
+ BLERemoteCharacteristic* pTemp = pThermoService->getCharacteristic(thermo_temp_uuid);
+ if (!pTemp) {
+ show("NO TEMP CHAR");
+ return 60;
+ }
+ show("SCw");
+ pTemp->writeValue(data->c_str(),data->length());
+ show("SCWr");
+ BLERemoteCharacteristic* pTime = pThermoService->getCharacteristic(thermo_time_uuid);
+ if (!pTime) {
+ show("NO TIME CHAR");
+ return 60;
+ }
+ std::string next_time = pTime->readValue();
+ show("SCWRd");
+ pClient->disconnect();
+ show("SCWRD");
+ return String(next_time.c_str()).toInt();
+ }
+ catch (...) {
+ show("Fail");
+ pClient->disconnect();
+ return ON_ERROR_SLEEP_TIME;
+ }
+}
+
+void setup() {
+ display.init();
+ display.connect();
+ display.displayOn();
+ display.clear();
+ show("setup");
+ BLEDevice::init("");
+ esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_ADV, BLE_POWER);
+ esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, BLE_POWER);
+ esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, BLE_POWER);
+ show("setup+bt");
+ enable_sensor(true);
+ show("setup+bt+sensor");
+}
+
+void teardown_and_sleep(int next_time) {
+ enable_sensor(false);
+ BLEDevice::uninit();
+ //esp_wifi_stop();
+ delay(2000);
+ esp_sleep_enable_timer_wakeup(next_time * uS_TO_S_FACTOR);
+ esp_deep_sleep_start();
+}
+
+void watchdog_cb() {
+ show("watchdog");
+ teardown_and_sleep(ON_ERROR_SLEEP_TIME);
+}
+
+void loop() {
+ Ticker watchdog_timer;
+ watchdog_timer.attach(WATCHDOG_SECONDS,watchdog_cb);
+
+ BLEScan* pBLEScan = BLEDevice::getScan();
+ MyAdvertisedDeviceCallbacks* cb = new MyAdvertisedDeviceCallbacks();
+ pBLEScan->setAdvertisedDeviceCallbacks(cb);
+ pBLEScan->setActiveScan(true);
+ show("s");
+ BLEScanResults foundDevices = pBLEScan->start(30);
+ int next_time;
+
+ if (cb->pServerAddress) {
+ show("S");
+
+ float humidity, temperature;
+ bool ok = read_sensor(&humidity,&temperature);
+ if (ok) {
+ String data = String(BLEDevice::getAddress().toString().c_str()) + " " + String(humidity) + " " + String(temperature) + "\n";
+ show(data);
+
+ next_time = send_data_and_get_time(cb->pServerAddress,&data);
+ }
+ else {
+ show("no thermo");
+ next_time=ON_ERROR_SLEEP_TIME;
+ }
+ }
+ else {
+ display.drawString(0,0,"s!");display.display();
+ next_time = NO_SERVER_SLEEP_TIME;
+ }
+
+ delete cb;
+
+ String nt = "Next time:";nt+=next_time;
+ display.drawString(0,20,nt);display.display();
+ teardown_and_sleep(next_time);
+
+ show("woken up");
+ delay(2000);
+}
diff --git a/trasmitter/.gitignore b/trasmitter/.gitignore
new file mode 100644
index 0000000..bd6f3a9
--- /dev/null
+++ b/trasmitter/.gitignore
@@ -0,0 +1,3 @@
+/arduino/build-*/
+/sender-chip
+
diff --git a/trasmitter/Makefile b/trasmitter/Makefile
new file mode 100644
index 0000000..b31025b
--- /dev/null
+++ b/trasmitter/Makefile
@@ -0,0 +1,10 @@
+CFLAGS = -Wall
+
+all: sender-chip setcap
+
+sender-chip: sender-chip.c
+
+setcap: sender-chip
+ sudo setcap CAP_SYS_NICE=eip $<
+
+.PHONY: setcap
diff --git a/trasmitter/README.rst.txt b/trasmitter/README.rst.txt
new file mode 100644
index 0000000..78200a4
--- /dev/null
+++ b/trasmitter/README.rst.txt
@@ -0,0 +1,42 @@
+Some links:
+
+* capturing radio signals
+ http://www.stevenhale.co.uk/main/2013/08/home-automation-reverse-engineering-a-worcester-bosch-dt10rf-wireless-thermostat/
+ https://damn.technology/controlling-british-gas-wr1-receiver-arduino
+ http://rossharper.net/2015/11/decoding-a-siemens-rcr10433-thermostat-signal-to-control-a-boiler-from-a-raspberry-pi/
+
+IMPORTANT: the transmitter prefers 3.3V, it stops working after a
+while on 5V.
+
+Reveng
+======
+
+Sampled at 192k samples/second, found that the transmissions had 3
+types of (presumably square) pulses:
+
+======== ======= ========
+name samples duration
+======== ======= ========
+narrow 200 ~ 1ms
+middle 300 ~ 1.5ms
+wide 400 ~ 2ms
+======== ======= ========
+
+The two sequences are:
+
+* ``nnnnnnWnWnnMnnMnnnnnWnnnnMnMWn``
+* ``nnnnnnWnWnnMnnMnnnnnnnnnnWMMWn``
+
+Actually no, the pulses are not ½ high and ½ low, they're shaped
+weird. The source code has the correct widths.
+
+Without Arduino
+===============
+
+The GPIO / XIO pins on NextThing's CHIP, even when driven via the `slow
+sysfs interface`_, seem to be fast enough for our purposes.
+
+See the ``sender-chip.pl`` test program.
+
+If we keep the ``*/value`` file open, we get good enough timing. The
+``sender-chip.c`` program works.
diff --git a/trasmitter/arduino/Makefile b/trasmitter/arduino/Makefile
new file mode 100644
index 0000000..9815090
--- /dev/null
+++ b/trasmitter/arduino/Makefile
@@ -0,0 +1,19 @@
+ARDMK_DIR = /home/dakkar/src/Arduino-Makefile
+ARDUINO_DIR = /usr/share/arduino
+MONITOR_PORT = /dev/ttyACM*
+CURRENT_DIR = $(basename $(CURDIR))
+AVR_TOOLS_DIR = /usr
+AVRDUDE_CONF = /etc/avrdude.conf
+
+PROJECT_DIR = $(CURDIR)
+BOARD_TAG = uno
+MONITOR_BAUDRATE = 115200
+
+CFLAGS_STD = -std=gnu11
+CXXFLAGS_STD = -std=gnu++11
+CXXFLAGS += -pedantic -Wall -Wextra
+
+include $(ARDMK_DIR)/Arduino.mk
+
+check-syntax:
+ $(CXX) -c -include Arduino.h -x c++ $(CXXFLAGS) $(CPPFLAGS) -fsyntax-only $(CHK_SOURCES)
diff --git a/trasmitter/arduino/sender.ino b/trasmitter/arduino/sender.ino
new file mode 100644
index 0000000..9373875
--- /dev/null
+++ b/trasmitter/arduino/sender.ino
@@ -0,0 +1,93 @@
+const uint16_t pulseScale = 520; // usec per sample unit
+
+// alternate HIGH and LOW, first one of each array is HIGH
+const uint8_t prologue[] = {
+ 1,1, 1,1, 1,1, 1,1, 1,1, 1,1,
+ 2,3, 1,1, 2,2, 1,1, 1,1, 2,1,
+ 1,1, 1,1, 1,2, 1,1, 1,1, 1,1,
+ 1,1, 1,1,
+};
+const size_t prologueSize = sizeof(prologue) / sizeof(uint8_t);
+
+const uint8_t epilogue[] = {
+ 1,2, 2,2, 1,3, // the last value doesn't much matter
+};
+const size_t epilogueSize = sizeof(epilogue) / sizeof(uint8_t);
+
+const uint8_t onSignal[] = {
+ 2,2, 1,1, 1,1, 1,1, 1,1, 2,1, 1,1,
+};
+const size_t onSize = sizeof(onSignal) / sizeof(uint8_t);
+
+const uint8_t offSignal[] = {
+ 1,1, 1,1, 1,1, 1,1, 1,1, 2,2, 2,1,
+};
+const size_t offSize = sizeof(offSignal) / sizeof(uint8_t);
+
+const int nTxPin = 7; // Arduino digital pin you're using for radio data.
+
+void transmitArray(const uint8_t pulses[], size_t pulseCount) {
+ for(size_t idx = 0; idx < pulseCount; idx+=2) {
+ digitalWrite(nTxPin, HIGH);
+ delayMicroseconds(pulseScale*pulses[idx]);
+
+ digitalWrite(nTxPin, LOW);
+ delayMicroseconds(pulseScale*pulses[idx+1]);
+ }
+}
+
+void transmitSignal(const uint8_t signal[], size_t signalSize) {
+ transmitArray(prologue,prologueSize);
+ transmitArray(signal,signalSize);
+ transmitArray(epilogue,epilogueSize);
+}
+
+void sendTrain(const uint8_t signal[], size_t signalSize) {
+ transmitSignal(signal,signalSize);
+ delay(1000);
+ transmitSignal(signal,signalSize);
+ delay(2000);
+ transmitSignal(signal,signalSize);
+}
+
+
+/**
+ * The setup() function is called when a sketch starts. Used to initialize
+ * variables, pin modes, start using libraries, etc. The setup function will
+ * only run once, after each powerup or reset of the Arduino board.
+ */
+void setup()
+{
+ pinMode(nTxPin, OUTPUT);
+ digitalWrite(nTxPin, LOW);
+
+ Serial.begin(9600);
+ Serial.println("Press 0 to turn off heating");
+ Serial.println("Press 1 to turn on heating");
+
+}
+
+
+/**
+ * The loop() function loops consecutively, allowing the program to change and
+ * respond. Used to actively control the Arduino board.
+ */
+void loop()
+{
+ if (Serial.available() > 0)
+ {
+ int nIncomming = Serial.read();
+ if (nIncomming == 49) { // char code for 1
+ Serial.println("ON");
+ sendTrain(onSignal,onSize);
+ }
+
+ if (nIncomming == 48) { // char code for 0
+ Serial.println("OFF");
+ sendTrain(offSignal,offSize);
+ }
+
+ Serial.println("Press 0 to turn off heating");
+ Serial.println("Press 1 to turn on heating");
+ }
+} \ No newline at end of file
diff --git a/trasmitter/sender-chip.c b/trasmitter/sender-chip.c
new file mode 100644
index 0000000..7ada0cf
--- /dev/null
+++ b/trasmitter/sender-chip.c
@@ -0,0 +1,146 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <sched.h>
+#include <inttypes.h>
+
+#define PIN "132"
+
+void init_pin() {
+ int fd = open("/sys/class/gpio/export",O_WRONLY);
+ char buf[16];
+ int len = sprintf(buf,"%s\n",PIN);
+ write(fd,buf,len);
+ close(fd);
+ fd = open("/sys/class/gpio/gpio" PIN "/direction",O_WRONLY);
+ write(fd,"out\n",4);
+ close(fd);
+}
+
+void deinit_pin() {
+ int fd = open("/sys/class/gpio/unexport",O_WRONLY);
+ char buf[16];
+ int len = sprintf(buf,"%s\n",PIN);
+ write(fd,buf,len);
+ close(fd);
+}
+
+int pin_fd;
+void write_pin(uint8_t value) {
+ if (!pin_fd) {
+ pin_fd = open("/sys/class/gpio/gpio" PIN "/value",O_WRONLY);
+ }
+ char buf[16];
+ int len = sprintf(buf,"%d\n",value);
+ write(pin_fd,buf,len);
+}
+
+void init_sched() {
+ struct sched_param sp;
+ sp.sched_priority=99;
+
+ // to make this work, sudo setcap CAP_SYS_NICE=eip clock
+ sched_setscheduler(0,SCHED_RR,&sp);
+}
+
+const int width=520000;
+struct timespec next_step;
+void send_array(const uint8_t values[],size_t len) {
+ if (next_step.tv_sec == 0) {
+ clock_gettime(CLOCK_REALTIME,&next_step);
+ }
+ uint8_t pin_value = 1;
+ for (int i=0; i<len; ++i) {
+ write_pin(pin_value);
+ pin_value = 1 - pin_value;
+
+ next_step.tv_nsec += width * values[i];
+
+ if (next_step.tv_nsec > 1000000000UL) {
+ next_step.tv_nsec -= 1000000000UL;
+ ++next_step.tv_sec;
+ }
+
+ int rc = clock_nanosleep(CLOCK_REALTIME,
+ TIMER_ABSTIME,
+ &next_step,
+ NULL);
+ if (rc) {
+ printf("problems: %d\n",rc);
+ }
+ }
+}
+void my_sleep(uint8_t seconds) {
+ next_step.tv_sec += seconds;
+
+ int rc = clock_nanosleep(CLOCK_REALTIME,
+ TIMER_ABSTIME,
+ &next_step,
+ NULL);
+ if (rc) {
+ printf("problems: %d\n",rc);
+ }
+}
+
+// alternate HIGH and LOW, first one of each array is HIGH
+const uint8_t prologue[] = {
+ 1,1, 1,1, 1,1, 1,1, 1,1, 1,1,
+ 2,3, 1,1, 2,2, 1,1, 1,1, 2,1,
+ 1,1, 1,1, 1,2, 1,1, 1,1, 1,1,
+ 1,1, 1,1,
+};
+const size_t prologueSize = sizeof(prologue) / sizeof(uint8_t);
+
+const uint8_t epilogue[] = {
+ 1,2, 2,2, 1,3, // the last value doesn't much matter
+};
+const size_t epilogueSize = sizeof(epilogue) / sizeof(uint8_t);
+
+const uint8_t onSignal[] = {
+ 2,2, 1,1, 1,1, 1,1, 1,1, 2,1, 1,1,
+};
+const size_t onSize = sizeof(onSignal) / sizeof(uint8_t);
+
+const uint8_t offSignal[] = {
+ 1,1, 1,1, 1,1, 1,1, 1,1, 2,2, 2,1,
+};
+const size_t offSize = sizeof(offSignal) / sizeof(uint8_t);
+
+void transmitSignal(const uint8_t signal[], size_t signalSize) {
+ send_array(prologue,prologueSize);
+ send_array(signal,signalSize);
+ send_array(epilogue,epilogueSize);
+}
+
+void sendTrain(const uint8_t signal[], size_t signalSize) {
+ transmitSignal(offSignal,offSize);
+ my_sleep(1);
+ transmitSignal(signal,signalSize);
+ my_sleep(2);
+ transmitSignal(offSignal,offSize);
+}
+
+int main(int argc,char **argv) {
+ if (argc != 2) {
+ fprintf(stderr,"thing 0/1\n");
+ return 1;
+ }
+
+ init_sched();
+ init_pin();
+ write_pin(0);
+
+ if (argv[1][0] == '1') {
+ sendTrain(onSignal,onSize);
+ }
+ else {
+ sendTrain(offSignal,offSize);
+ }
+
+ deinit_pin();
+
+ return 0;
+}
diff --git a/trasmitter/sender-chip.pl b/trasmitter/sender-chip.pl
new file mode 100644
index 0000000..f6d3dd3
--- /dev/null
+++ b/trasmitter/sender-chip.pl
@@ -0,0 +1,91 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Time::HiRes qw(usleep sleep gettimeofday tv_interval);
+
+# my $base = do {
+# open my $fh,'<','/sys/class/gpio/gpiochip405/base' or die "can't get base: $!";
+# my $line = <$fh>;
+# chomp($line);
+# $line;
+# };
+
+sub gpio_enable {
+ my ($pin,$state) = @_;
+
+ if ($state) {
+ open my $fh,'>','/sys/class/gpio/export' or die "Can't export: $!";
+ print $fh $pin,"\n";
+ }
+ else {
+ open my $fh,'>','/sys/class/gpio/unexport' or die "Can't unexport: $!";
+ print $fh $pin,"\n";
+ }
+}
+
+sub gpio_direction {
+ my ($pin,$direction) = @_;
+
+ my $file = "/sys/class/gpio/gpio$pin/direction";
+ open my $fh,'>',$file
+ or die "Can't direction $file: $!";
+ print $fh ($direction ? 'out' : 'in' ),"\n";
+}
+
+sub gpio_write {
+ my ($pin,$value) = @_;
+
+ open my $fh,'>',"/sys/class/gpio/gpio$pin/value"
+ or die "Can't write: $!";
+ print $fh $value,"\n";
+}
+
+my $pin = 132; # CSID0
+#my $pin = $base+0; # XIO0
+
+gpio_enable($pin,1);
+gpio_direction($pin,1);
+gpio_write($pin,0);
+$SIG{INT} = sub {warn"disabling";gpio_enable($pin,0) };
+END { warn"disabling";gpio_enable($pin,0) }
+
+my $width = 370; # this seems to provide pulse widths close enough to
+ # what we need, it's 106 samples at 192kHz
+
+sub send_array {
+ my $state = 1;
+ for (@_) {
+ gpio_write($pin,$state);
+ usleep($width*$_);
+ $state = $state ? 0 : 1;
+ }
+}
+
+my @prologue = (
+ 1,1, 1,1, 1,1, 1,1, 1,1, 1,1,
+ 2,3, 1,1, 2,2, 1,1, 1,1, 2,1,
+ 1,1, 1,1, 1,2, 1,1, 1,1, 1,1,
+ 1,1, 1,1,
+);
+my @epilogue = (
+ 1,2, 2,2, 1,3, # the last value doesn't much matter
+);
+
+my @on_signal = (
+ 2,2, 1,1, 1,1, 1,1, 1,1, 2,1, 1,1,
+);
+my @off_signal = (
+ 1,1, 1,1, 1,1, 1,1, 1,1, 2,2, 2,1,
+);
+
+my @train = (
+ @prologue,
+ ( $ARGV[0] ? @on_signal : @off_signal ),
+ @epilogue,
+);
+
+send_array(@train);
+sleep(1);
+send_array(@train);
+sleep(2);
+send_array(@train);