Finish bluetooth server advertise and machine id

This commit is contained in:
Simon Stürz 2018-03-13 12:47:27 +01:00
parent a81497e760
commit ccf1c10913
5 changed files with 57 additions and 31 deletions

View File

@ -1,19 +1,22 @@
# nymea-networkmanager
This daemon allows to set up the wireless network using a bluetooth LE connection.
This daemon allows to set up the wireless network using a bluetooth LE connection. The daemon will automatically start a bluetooth low energy server
if the system is currently not connected to any network. Once the system is connected, the daemon will shutdown the bluetooth server.
# Bluetooth GATT profile
-------------------------------------------
In order to connect to nymea-networkmanager using bluetooth low energy, once has to perform a bluetooth discovery, filter for all low energy devices and connect to the device with the name `nymea`. The remote address type for connecting to `nymea-networkmanager` is `public`.
In order to connect to nymea-networkmanager using bluetooth low energy, once has to perform a bluetooth discovery, filter for all low energy
devices and connect to the device with the name `nymea`. The remote address type for connecting to `nymea-networkmanager` is `public`.
## Behaviour
## Notifications
In order to enable/disable the notification for a characteristic with the `notify` flag, a client has to write the value `0x0100` for enabling and `0x0000` for disabling to the descriptor `0x2902` of the corresponding characteristic.
In order to enable/disable the notification for a characteristic with the `notify` flag, a client has to write the value `0x0100` for
enabling and `0x0000` for disabling to the descriptor `0x2902` of the corresponding characteristic.
## Services:
@ -35,7 +38,8 @@ In order to enable/disable the notification for a characteristic with the `notif
#### **S**: Generic Access
> Default service for Bluetooth LE GATT devices. More information can be found [here](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.generic_access.xml).
> Default service for Bluetooth LE GATT devices. More information can be
found [here](https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.service.generic_access.xml).
#### **S**: Generic Attribute

View File

@ -1,5 +1,5 @@
[Unit]
Description=Daemon for nymea to configure wifi network using Bluetooth LE.
Description=Daemon for nymea to configure wifi network using a Bluetooth LE connection
Documentation=https://github.com/guh/nymea-networkmanager
After=network.target

View File

@ -26,9 +26,8 @@
#include <QJsonDocument>
#include <QCoreApplication>
BluetoothServer::BluetoothServer(const QString &machineId, QObject *parent) :
QObject(parent),
m_machineId(machineId)
BluetoothServer::BluetoothServer(QObject *parent) :
QObject(parent)
{
}
@ -44,6 +43,26 @@ BluetoothServer::~BluetoothServer()
}
QString BluetoothServer::machineId() const
{
return m_machineId;
}
void BluetoothServer::setMachineId(const QString &machineId)
{
m_machineId = machineId;
}
QString BluetoothServer::advertiseName() const
{
return m_advertiseName;
}
void BluetoothServer::setAdvertiseName(const QString &advertiseName)
{
m_advertiseName = advertiseName;
}
bool BluetoothServer::running() const
{
return m_running;
@ -63,28 +82,23 @@ QLowEnergyServiceData BluetoothServer::deviceInformationServiceData()
// Model number string 0x2a24
QLowEnergyCharacteristicData modelNumberCharData;
modelNumberCharData.setUuid(QBluetoothUuid::ModelNumberString);
if (m_machineId.isEmpty()) {
modelNumberCharData.setValue(QString("N.A.").toUtf8());
} else {
modelNumberCharData.setValue(m_machineId.toUtf8());
}
modelNumberCharData.setValue(m_machineId.toUtf8());
modelNumberCharData.setProperties(QLowEnergyCharacteristic::Read);
serviceData.addCharacteristic(modelNumberCharData);
// // Firmware revision string 0x2a26
// QLowEnergyCharacteristicData firmwareRevisionCharData;
// firmwareRevisionCharData.setUuid(QBluetoothUuid::FirmwareRevisionString);
// firmwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
// firmwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
// serviceData.addCharacteristic(firmwareRevisionCharData);
// Firmware revision string 0x2a26
QLowEnergyCharacteristicData firmwareRevisionCharData;
firmwareRevisionCharData.setUuid(QBluetoothUuid::FirmwareRevisionString);
firmwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
firmwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
serviceData.addCharacteristic(firmwareRevisionCharData);
// // Hardware revision string 0x2a27
// QLowEnergyCharacteristicData hardwareRevisionCharData;
// hardwareRevisionCharData.setUuid(QBluetoothUuid::HardwareRevisionString);
// hardwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
// hardwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
// serviceData.addCharacteristic(hardwareRevisionCharData);
// Hardware revision string 0x2a27
QLowEnergyCharacteristicData hardwareRevisionCharData;
hardwareRevisionCharData.setUuid(QBluetoothUuid::HardwareRevisionString);
hardwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
hardwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
serviceData.addCharacteristic(hardwareRevisionCharData);
// Software revision string 0x2a28
QLowEnergyCharacteristicData softwareRevisionCharData;
@ -346,7 +360,6 @@ void BluetoothServer::start(WirelessNetworkDevice *wirelessDevice)
m_localDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
m_localDevice->powerOn();
// Bluetooth low energy periperal controller
m_controller = QLowEnergyController::createPeripheral(this);
connect(m_controller, &QLowEnergyController::stateChanged, this, &BluetoothServer::onControllerStateChanged);
@ -366,7 +379,7 @@ void BluetoothServer::start(WirelessNetworkDevice *wirelessDevice)
QLowEnergyAdvertisingData advertisingData;
advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
advertisingData.setIncludePowerLevel(true);
advertisingData.setLocalName("nymea");
advertisingData.setLocalName(m_advertiseName);
// TODO: set guh manufacturer SIG data

View File

@ -47,14 +47,21 @@ class BluetoothServer : public QObject
Q_OBJECT
public:
explicit BluetoothServer(const QString &machineId, QObject *parent = 0);
explicit BluetoothServer(QObject *parent = 0);
~BluetoothServer();
QString machineId() const;
void setMachineId(const QString &machineId);
QString advertiseName() const;
void setAdvertiseName(const QString &advertiseName);
bool running() const;
bool connected() const;
private:
QString m_machineId;
QString m_machineId = "nymea-box";
QString m_advertiseName = "nymea";
QBluetoothLocalDevice *m_localDevice = nullptr;
QLowEnergyController *m_controller = nullptr;

View File

@ -88,7 +88,7 @@ Core::Core(QObject *parent) :
connect(m_networkManager, &NetworkManager::availableChanged, this, &Core::onNetworkManagerAvailableChanged);
connect(m_networkManager, &NetworkManager::stateChanged, this, &Core::onNetworkManagerStateChanged);
m_bluetoothServer = new BluetoothServer("nymea-box", this);
m_bluetoothServer = new BluetoothServer(this);
connect(m_bluetoothServer, &BluetoothServer::runningChanged, this, &Core::onBluetoothServerRunningChanged);
connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged);
@ -149,6 +149,8 @@ void Core::startService()
// Start the bluetooth server for this wireless device
qCDebug(dcApplication()) << "Start bluetooth service";
m_bluetoothServer->setAdvertiseName(m_advertiseName);
m_bluetoothServer->setMachineId(m_platformName);
m_bluetoothServer->start(m_networkManager->wirelessNetworkDevices().first());
}