summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2019-03-02 15:34:22 +0000
committerdakkar <dakkar@thenautilus.net>2019-03-02 15:34:22 +0000
commit426c75cb5f68f226fc30ce41ea58d7b1127d97f5 (patch)
treeb1b5b8ac72d7c09e31bb352fbdf196e380f03665
parentcompile for feather (diff)
downloadthermostat-426c75cb5f68f226fc30ce41ea58d7b1127d97f5.tar.gz
thermostat-426c75cb5f68f226fc30ce41ea58d7b1127d97f5.tar.bz2
thermostat-426c75cb5f68f226fc30ce41ea58d7b1127d97f5.zip
log via serial
-rw-r--r--sensor/thermostat.ino19
1 files changed, 19 insertions, 0 deletions
diff --git a/sensor/thermostat.ino b/sensor/thermostat.ino
index 4f65c60..08b37f1 100644
--- a/sensor/thermostat.ino
+++ b/sensor/thermostat.ino
@@ -68,29 +68,41 @@ bool read_sensor(float* humidity, float* temperature) {
uint32_t send_data_and_get_time(BLEAddress* pAddress,String* data) {
BLEClient* pClient = BLEDevice::createClient();
+ Serial.println("connecting");
bool ok = pClient->connect(*pAddress);
if (!ok) {
+ Serial.println("connect fail");
return ON_ERROR_SLEEP_TIME;
}
+ Serial.println("connected");
try {
BLERemoteService* pThermoService = pClient->getService(thermo_service_uuid);
if (!pThermoService) {
+ Serial.println("failed to find service");
return 60;
}
BLERemoteCharacteristic* pTemp = pThermoService->getCharacteristic(thermo_temp_uuid);
if (!pTemp) {
+ Serial.println("failed to find writing characteristic");
return 60;
}
+ Serial.println("sending data");
pTemp->writeValue(data->c_str(),data->length());
+ Serial.println("sent");
BLERemoteCharacteristic* pTime = pThermoService->getCharacteristic(thermo_time_uuid);
if (!pTime) {
+ Serial.println("failed to find reading characteristic");
return 60;
}
+ Serial.println("receiving data");
std::string next_time = pTime->readValue();
+ Serial.println("received");
pClient->disconnect();
+ Serial.println("done");
return String(next_time.c_str()).toInt();
}
catch (...) {
+ Serial.println("general fail");
pClient->disconnect();
return ON_ERROR_SLEEP_TIME;
}
@@ -102,6 +114,7 @@ void setup() {
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_SCAN, BLE_POWER);
esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, BLE_POWER);
enable_sensor(true);
+ Serial.begin(9600);
}
void teardown_and_sleep(int next_time) {
@@ -114,6 +127,7 @@ void teardown_and_sleep(int next_time) {
}
void watchdog_cb() {
+ Serial.println("watchdog");
teardown_and_sleep(ON_ERROR_SLEEP_TIME);
}
@@ -121,6 +135,7 @@ void loop() {
Ticker watchdog_timer;
watchdog_timer.attach(WATCHDOG_SECONDS,watchdog_cb);
+ Serial.println("start BLE scan");
BLEScan* pBLEScan = BLEDevice::getScan();
MyAdvertisedDeviceCallbacks* cb = new MyAdvertisedDeviceCallbacks();
pBLEScan->setAdvertisedDeviceCallbacks(cb);
@@ -129,6 +144,7 @@ void loop() {
int next_time;
if (cb->pServerAddress) {
+ Serial.println("found BLE server");
float humidity, temperature;
bool ok = read_sensor(&humidity,&temperature);
int batteryLevel = analogRead(VBAT_PIN);
@@ -138,13 +154,16 @@ void loop() {
+ String(humidity) + " "
+ String(temperature) + " "
+ String(batteryLevel) + "\n";
+ Serial.println(data);
next_time = send_data_and_get_time(cb->pServerAddress,&data);
}
else {
+ Serial.println("sensor error");
next_time=ON_ERROR_SLEEP_TIME;
}
}
else {
+ Serial.println("failed to find BLE server");
next_time = NO_SERVER_SLEEP_TIME;
}