#include #include #include #include "Bluetooth.h" using namespace std; using namespace trygvis::bluetooth; typedef boost::uuids::uuid uuid_t; #define BLUETOOTH_UUID_INITIALIZER \ { \ 0x00, 0x00, 0x00, 0x00, \ 0x00, 0x00, \ 0x10, 0x00, \ 0x80, 0x00, \ 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb \ }; uuid_t trygvis_io_base_uuid = { 0x32, 0xd0, 0x00, 0x00, 0x03, 0x5d, 0x59, 0xc5, 0x70, 0xd3, 0xbc, 0x8e, 0x4a, 0x1f, 0xd8, 0x3f}; uuid_t soil_moisture_service = makeUuid(trygvis_io_base_uuid, 0x00, 0x10); int main(int argc, char *argv[]) { if (argc != 2) { cerr << "usage: " << argv[0] << " [mac]" << endl; return EXIT_FAILURE; } int e; BluetoothSystem bluetoothSystem; try { Mac mac = Mac::parseMac(argv[1]); BluetoothAdapter &adapter = getAdapter(0); BluetoothDevice &device = adapter.getDevice(mac); cout << "Connecting to device: " << device.mac().str() << endl; device.connect(); device.discoverServices(); boost::optional service = device.findService(soil_moisture_service); if (!service) { cout << "The device is missing the soil moisture service" << endl; return EXIT_FAILURE; } device.disconnect(); return EXIT_SUCCESS; } catch (std::runtime_error ex) { W << "std::runtime_error: " << ex.what(); return EXIT_FAILURE; } catch (std::exception ex) { W << "std::exception: " << ex.what(); return EXIT_FAILURE; } }