Restore ability to set a different ssid.
Add on and off commands.
This commit is contained in:
parent
df5cc31355
commit
de16fea254
|
@ -43,10 +43,12 @@ void ConsoleReader::run()
|
||||||
case 'a':
|
case 'a':
|
||||||
{
|
{
|
||||||
std::cout << "Please set your Orvibo socket to pair mode (rapidly blinking blue light) and wait until new wifi network (WiWo-S20) appears" << std::endl;
|
std::cout << "Please set your Orvibo socket to pair mode (rapidly blinking blue light) and wait until new wifi network (WiWo-S20) appears" << std::endl;
|
||||||
std::string password;
|
std::string ssid, password;
|
||||||
|
std::cout << "Wireless name (\"c\" for current wifi): ";
|
||||||
|
std::cin >> ssid;
|
||||||
std::cout << "Password: ";
|
std::cout << "Password: ";
|
||||||
std::cin >> password;
|
std::cin >> password;
|
||||||
Server *server = new Server(48899, QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899
|
Server *server = new Server(48899, QByteArray::fromStdString(ssid), QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'A':
|
case 'A':
|
||||||
|
@ -75,6 +77,12 @@ void ConsoleReader::run()
|
||||||
case 'p':
|
case 'p':
|
||||||
(*sockets) [number]->toggle();
|
(*sockets) [number]->toggle();
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
if (command == "off")
|
||||||
|
(*sockets) [number]->powerOff();
|
||||||
|
else if (command == "on")
|
||||||
|
(*sockets) [number]->powerOn();
|
||||||
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
{
|
{
|
||||||
std::string password;
|
std::string password;
|
||||||
|
|
2
s20.pro
2
s20.pro
|
@ -1,4 +1,4 @@
|
||||||
SOURCES = consolereader.cpp main.cpp server.cpp socket.cpp
|
SOURCES = consolereader.cpp main.cpp server.cpp socket.cpp
|
||||||
HEADERS = consolereader.h server.h socket.h
|
HEADERS = consolereader.h server.h socket.h
|
||||||
QT += network
|
QT += network
|
||||||
CONFIG += c++11
|
CONFIG += console c++11
|
||||||
|
|
|
@ -40,14 +40,19 @@ Server::Server ( std::vector<Socket*> *sockets_vector )
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::Server(uint16_t port, QByteArray password)
|
Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
|
||||||
{
|
{
|
||||||
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
|
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
|
||||||
QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
QNetworkConfiguration *cfg = new QNetworkConfiguration;
|
||||||
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
|
||||||
ncm->updateConfigurations();
|
ncm->updateConfigurations();
|
||||||
*cfgInitial = ncm->defaultConfiguration();
|
*cfgInitial = ncm->defaultConfiguration();
|
||||||
QByteArray ssid = cfgInitial->name().toLocal8Bit();
|
|
||||||
|
if (ssid == "c")
|
||||||
|
{
|
||||||
|
ssid = cfgInitial->name().toLocal8Bit();
|
||||||
|
qDebug() << "SSID unspecified, using current network: " << ssid;
|
||||||
|
}
|
||||||
|
|
||||||
bool stop = false;
|
bool stop = false;
|
||||||
while ( !stop )
|
while ( !stop )
|
||||||
|
|
2
server.h
2
server.h
|
@ -30,7 +30,7 @@ Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Server ( std::vector<Socket*> *sockets_vector );
|
Server ( std::vector<Socket*> *sockets_vector );
|
||||||
Server ( uint16_t port, QByteArray password );
|
Server ( uint16_t port, QByteArray ssid, QByteArray password );
|
||||||
~Server();
|
~Server();
|
||||||
|
|
||||||
void discoverSockets();
|
void discoverSockets();
|
||||||
|
|
14
socket.cpp
14
socket.cpp
|
@ -127,6 +127,20 @@ void Socket::toggle()
|
||||||
sendDatagram ( powered ? PowerOff : PowerOn );
|
sendDatagram ( powered ? PowerOff : PowerOn );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Socket::powerOff()
|
||||||
|
{
|
||||||
|
if (powered)
|
||||||
|
sendDatagram ( PowerOff );
|
||||||
|
Q_EMIT stateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Socket::powerOn()
|
||||||
|
{
|
||||||
|
if (!powered)
|
||||||
|
sendDatagram ( PowerOn );
|
||||||
|
Q_EMIT stateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void Socket::changeSocketName ( QString newName )
|
void Socket::changeSocketName ( QString newName )
|
||||||
{
|
{
|
||||||
QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);
|
QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);
|
||||||
|
|
2
socket.h
2
socket.h
|
@ -41,6 +41,8 @@ public:
|
||||||
Socket ( QHostAddress, QByteArray ); // from discovery packet
|
Socket ( QHostAddress, QByteArray ); // from discovery packet
|
||||||
~Socket();
|
~Socket();
|
||||||
void toggle();
|
void toggle();
|
||||||
|
void powerOff();
|
||||||
|
void powerOn();
|
||||||
void discover();
|
void discover();
|
||||||
void tableData();
|
void tableData();
|
||||||
void changeSocketName ( QString newName );
|
void changeSocketName ( QString newName );
|
||||||
|
|
Loading…
Reference in New Issue