Finish bluetooth server advertise and machine id
This commit is contained in:
parent
a81497e760
commit
ccf1c10913
12
README.md
12
README.md
@ -1,19 +1,22 @@
|
|||||||
# nymea-networkmanager
|
# 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
|
# 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
|
## Behaviour
|
||||||
|
|
||||||
|
|
||||||
## Notifications
|
## 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:
|
## Services:
|
||||||
|
|
||||||
@ -35,7 +38,8 @@ In order to enable/disable the notification for a characteristic with the `notif
|
|||||||
|
|
||||||
#### **S**: Generic Access
|
#### **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
|
#### **S**: Generic Attribute
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[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
|
Documentation=https://github.com/guh/nymea-networkmanager
|
||||||
After=network.target
|
After=network.target
|
||||||
|
|
||||||
|
|||||||
@ -26,9 +26,8 @@
|
|||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
BluetoothServer::BluetoothServer(const QString &machineId, QObject *parent) :
|
BluetoothServer::BluetoothServer(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent)
|
||||||
m_machineId(machineId)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -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
|
bool BluetoothServer::running() const
|
||||||
{
|
{
|
||||||
return m_running;
|
return m_running;
|
||||||
@ -63,28 +82,23 @@ QLowEnergyServiceData BluetoothServer::deviceInformationServiceData()
|
|||||||
// Model number string 0x2a24
|
// Model number string 0x2a24
|
||||||
QLowEnergyCharacteristicData modelNumberCharData;
|
QLowEnergyCharacteristicData modelNumberCharData;
|
||||||
modelNumberCharData.setUuid(QBluetoothUuid::ModelNumberString);
|
modelNumberCharData.setUuid(QBluetoothUuid::ModelNumberString);
|
||||||
if (m_machineId.isEmpty()) {
|
modelNumberCharData.setValue(m_machineId.toUtf8());
|
||||||
modelNumberCharData.setValue(QString("N.A.").toUtf8());
|
|
||||||
} else {
|
|
||||||
modelNumberCharData.setValue(m_machineId.toUtf8());
|
|
||||||
}
|
|
||||||
|
|
||||||
modelNumberCharData.setProperties(QLowEnergyCharacteristic::Read);
|
modelNumberCharData.setProperties(QLowEnergyCharacteristic::Read);
|
||||||
serviceData.addCharacteristic(modelNumberCharData);
|
serviceData.addCharacteristic(modelNumberCharData);
|
||||||
|
|
||||||
// // Firmware revision string 0x2a26
|
// Firmware revision string 0x2a26
|
||||||
// QLowEnergyCharacteristicData firmwareRevisionCharData;
|
QLowEnergyCharacteristicData firmwareRevisionCharData;
|
||||||
// firmwareRevisionCharData.setUuid(QBluetoothUuid::FirmwareRevisionString);
|
firmwareRevisionCharData.setUuid(QBluetoothUuid::FirmwareRevisionString);
|
||||||
// firmwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
|
firmwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
|
||||||
// firmwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
|
firmwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
|
||||||
// serviceData.addCharacteristic(firmwareRevisionCharData);
|
serviceData.addCharacteristic(firmwareRevisionCharData);
|
||||||
|
|
||||||
// // Hardware revision string 0x2a27
|
// Hardware revision string 0x2a27
|
||||||
// QLowEnergyCharacteristicData hardwareRevisionCharData;
|
QLowEnergyCharacteristicData hardwareRevisionCharData;
|
||||||
// hardwareRevisionCharData.setUuid(QBluetoothUuid::HardwareRevisionString);
|
hardwareRevisionCharData.setUuid(QBluetoothUuid::HardwareRevisionString);
|
||||||
// hardwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
|
hardwareRevisionCharData.setValue(QString("1.0.0").toUtf8());
|
||||||
// hardwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
|
hardwareRevisionCharData.setProperties(QLowEnergyCharacteristic::Read);
|
||||||
// serviceData.addCharacteristic(hardwareRevisionCharData);
|
serviceData.addCharacteristic(hardwareRevisionCharData);
|
||||||
|
|
||||||
// Software revision string 0x2a28
|
// Software revision string 0x2a28
|
||||||
QLowEnergyCharacteristicData softwareRevisionCharData;
|
QLowEnergyCharacteristicData softwareRevisionCharData;
|
||||||
@ -346,7 +360,6 @@ void BluetoothServer::start(WirelessNetworkDevice *wirelessDevice)
|
|||||||
m_localDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
|
m_localDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
|
||||||
m_localDevice->powerOn();
|
m_localDevice->powerOn();
|
||||||
|
|
||||||
|
|
||||||
// Bluetooth low energy periperal controller
|
// Bluetooth low energy periperal controller
|
||||||
m_controller = QLowEnergyController::createPeripheral(this);
|
m_controller = QLowEnergyController::createPeripheral(this);
|
||||||
connect(m_controller, &QLowEnergyController::stateChanged, this, &BluetoothServer::onControllerStateChanged);
|
connect(m_controller, &QLowEnergyController::stateChanged, this, &BluetoothServer::onControllerStateChanged);
|
||||||
@ -366,7 +379,7 @@ void BluetoothServer::start(WirelessNetworkDevice *wirelessDevice)
|
|||||||
QLowEnergyAdvertisingData advertisingData;
|
QLowEnergyAdvertisingData advertisingData;
|
||||||
advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
|
advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
|
||||||
advertisingData.setIncludePowerLevel(true);
|
advertisingData.setIncludePowerLevel(true);
|
||||||
advertisingData.setLocalName("nymea");
|
advertisingData.setLocalName(m_advertiseName);
|
||||||
|
|
||||||
// TODO: set guh manufacturer SIG data
|
// TODO: set guh manufacturer SIG data
|
||||||
|
|
||||||
|
|||||||
@ -47,14 +47,21 @@ class BluetoothServer : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit BluetoothServer(const QString &machineId, QObject *parent = 0);
|
explicit BluetoothServer(QObject *parent = 0);
|
||||||
~BluetoothServer();
|
~BluetoothServer();
|
||||||
|
|
||||||
|
QString machineId() const;
|
||||||
|
void setMachineId(const QString &machineId);
|
||||||
|
|
||||||
|
QString advertiseName() const;
|
||||||
|
void setAdvertiseName(const QString &advertiseName);
|
||||||
|
|
||||||
bool running() const;
|
bool running() const;
|
||||||
bool connected() const;
|
bool connected() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_machineId;
|
QString m_machineId = "nymea-box";
|
||||||
|
QString m_advertiseName = "nymea";
|
||||||
QBluetoothLocalDevice *m_localDevice = nullptr;
|
QBluetoothLocalDevice *m_localDevice = nullptr;
|
||||||
QLowEnergyController *m_controller = nullptr;
|
QLowEnergyController *m_controller = nullptr;
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ Core::Core(QObject *parent) :
|
|||||||
connect(m_networkManager, &NetworkManager::availableChanged, this, &Core::onNetworkManagerAvailableChanged);
|
connect(m_networkManager, &NetworkManager::availableChanged, this, &Core::onNetworkManagerAvailableChanged);
|
||||||
connect(m_networkManager, &NetworkManager::stateChanged, this, &Core::onNetworkManagerStateChanged);
|
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::runningChanged, this, &Core::onBluetoothServerRunningChanged);
|
||||||
connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged);
|
connect(m_bluetoothServer, &BluetoothServer::connectedChanged, this, &Core::onBluetoothServerConnectedChanged);
|
||||||
|
|
||||||
@ -149,6 +149,8 @@ void Core::startService()
|
|||||||
|
|
||||||
// Start the bluetooth server for this wireless device
|
// Start the bluetooth server for this wireless device
|
||||||
qCDebug(dcApplication()) << "Start bluetooth service";
|
qCDebug(dcApplication()) << "Start bluetooth service";
|
||||||
|
m_bluetoothServer->setAdvertiseName(m_advertiseName);
|
||||||
|
m_bluetoothServer->setMachineId(m_platformName);
|
||||||
m_bluetoothServer->start(m_networkManager->wirelessNetworkDevices().first());
|
m_bluetoothServer->start(m_networkManager->wirelessNetworkDevices().first());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user