diff options
author | dakkar <dakkar@thenautilus.net> | 2018-03-31 17:08:42 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-03-31 17:08:42 +0100 |
commit | 39ed3c1e6b35bad02618d958b425cf0b96fd7b10 (patch) | |
tree | da7f9b22c479bfbeaf0ddffd26d3b0655d2723de /src/Server.cpp | |
parent | general autotools bump (diff) | |
download | gobbledegook-39ed3c1e6b35bad02618d958b425cf0b96fd7b10.tar.gz gobbledegook-39ed3c1e6b35bad02618d958b425cf0b96fd7b10.tar.bz2 gobbledegook-39ed3c1e6b35bad02618d958b425cf0b96fd7b10.zip |
closer to what I want
* setting the temperature just prints it out
* asking for the next time to sample returns a constant (later, it
will read from stdin)
with this, I can wrap this program with `IPC::Run` or similar, and write
all the logic in Perl!
the esp32 will send its own device id with the temperature, and we can
safely assume that the request for "next time" will come from the same
device
Diffstat (limited to 'src/Server.cpp')
-rw-r--r-- | src/Server.cpp | 25 |
1 files changed, 9 insertions, 16 deletions
diff --git a/src/Server.cpp b/src/Server.cpp index f3464c6..bdc98a9 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -294,20 +294,20 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam .gattServiceBegin("thermo", "11111111-2222-3333-4444-000000000000") // Characteristic: String value - .gattCharacteristicBegin("room1", "11111111-2222-3333-4444-000000000001", {"read", "write"}) + .gattCharacteristicBegin("temperature", "11111111-2222-3333-4444-000000000001", {"read","write"}) // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - const char *temperature = self.getDataPointer<const char*>("room-1", ""); - self.methodReturnValue(pInvocation, temperature, true); + const char *fake_temp = "0"; + self.methodReturnValue(pInvocation, fake_temp, true); }) // Standard characteristic "WriteValue" method call .onWriteValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { GVariant *pValue = g_variant_get_child_value(pParameters, 0); - self.setDataPointer("room-1", Utils::stringFromGVariantByteArray(pValue).c_str()); + self.setDataPointer("temperature", Utils::stringFromGVariantByteArray(pValue).c_str()); }) // GATT Descriptor: Characteristic User Description (0x2901) @@ -318,7 +318,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard descriptor "ReadValue" method call .onReadValue(DESCRIPTOR_METHOD_CALLBACK_LAMBDA { - const char *pDescription = "temperature in room 1"; + const char *pDescription = "temperature in a room"; self.methodReturnValue(pInvocation, pDescription, true); }) @@ -327,20 +327,13 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam .gattCharacteristicEnd() // Characteristic: String value - .gattCharacteristicBegin("room2", "11111111-2222-3333-4444-000000000002", {"read", "write"}) + .gattCharacteristicBegin("time_to_next_reading", "11111111-2222-3333-4444-000000000002", {"read"}) // Standard characteristic "ReadValue" method call .onReadValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA { - const char *temperature = self.getDataPointer<const char*>("room-2", ""); - self.methodReturnValue(pInvocation, temperature, true); - }) - - // Standard characteristic "WriteValue" method call - .onWriteValue(CHARACTERISTIC_METHOD_CALLBACK_LAMBDA - { - GVariant *pValue = g_variant_get_child_value(pParameters, 0); - self.setDataPointer("room-2", Utils::stringFromGVariantByteArray(pValue).c_str()); + const char *time = self.getDataPointer<const char*>("time-to-next-sample", ""); + self.methodReturnValue(pInvocation, time, true); }) // GATT Descriptor: Characteristic User Description (0x2901) @@ -351,7 +344,7 @@ Server::Server(const std::string &serviceName, const std::string &advertisingNam // Standard descriptor "ReadValue" method call .onReadValue(DESCRIPTOR_METHOD_CALLBACK_LAMBDA { - const char *pDescription = "temperature in room 2"; + const char *pDescription = "time (in seconds) to wait before sending the next temperature reading"; self.methodReturnValue(pInvocation, pDescription, true); }) |