From d5d75064556d33b46a1e3808374d54255098d04c Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 2 Mar 2019 15:18:57 +0000 Subject: no more display --- sensor/Makefile | 2 +- sensor/thermostat.ino | 51 ++++----------------------------------------------- 2 files changed, 5 insertions(+), 48 deletions(-) diff --git a/sensor/Makefile b/sensor/Makefile index 43cfe2b..ae2c918 100644 --- a/sensor/Makefile +++ b/sensor/Makefile @@ -1,5 +1,5 @@ SKETCH = thermostat.ino -CUSTOM_LIBS = DHTesp esp8266-oled-ssd1306 patchedBLE +CUSTOM_LIBS = DHTesp patchedBLE UPLOAD_PORT = /dev/ttyUSB0 # this is the board with the OLED diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino index 23bc610..20496bc 100644 --- a/sensor/thermostat.ino +++ b/sensor/thermostat.ino @@ -1,6 +1,5 @@ #include #include -#include "SSD1306.h" #include "DHTesp.h" #include #include "BLEDevice.h" @@ -19,15 +18,8 @@ static BLEUUID thermo_time_uuid("11111111-2222-3333-4444-000000000002"); #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; @@ -65,14 +57,6 @@ bool read_sensor(float* humidity, float* temperature) { *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; @@ -80,60 +64,40 @@ bool read_sensor(float* humidity, float* temperature) { 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) { @@ -146,7 +110,6 @@ void teardown_and_sleep(int next_time) { } void watchdog_cb() { - show("watchdog"); teardown_and_sleep(ON_ERROR_SLEEP_TIME); } @@ -158,37 +121,31 @@ void loop() { 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); - + String data = String(BLEDevice::getAddress().toString().c_str()) + " " + + String(humidity) + " " + + String(temperature) + " " + + String(batteryLevel) + "\n"; 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); } -- cgit v1.2.3