Browse Source

Restore ability to set a different ssid.

Add on and off commands.
master
Andrius Štikonas 4 years ago
parent
commit
de16fea254
6 changed files with 35 additions and 6 deletions
  1. +10
    -2
      consolereader.cpp
  2. +1
    -1
      s20.pro
  3. +7
    -2
      server.cpp
  4. +1
    -1
      server.h
  5. +14
    -0
      socket.cpp
  6. +2
    -0
      socket.h

+ 10
- 2
consolereader.cpp View File

@@ -43,10 +43,12 @@ void ConsoleReader::run()
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::string password;
std::string ssid, password;
std::cout << "Wireless name (\"c\" for current wifi): ";
std::cin >> ssid;
std::cout << "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;
}
case 'A':
@@ -75,6 +77,12 @@ void ConsoleReader::run()
case 'p':
(*sockets) [number]->toggle();
break;
case 'o':
if (command == "off")
(*sockets) [number]->powerOff();
else if (command == "on")
(*sockets) [number]->powerOn();
break;
case 'P':
{
std::string password;

+ 1
- 1
s20.pro View File

@@ -1,4 +1,4 @@
SOURCES = consolereader.cpp main.cpp server.cpp socket.cpp
HEADERS = consolereader.h server.h socket.h
QT += network
CONFIG += c++11
CONFIG += console c++11

+ 7
- 2
server.cpp View File

@@ -40,14 +40,19 @@ Server::Server ( std::vector<Socket*> *sockets_vector )
start();
}

Server::Server(uint16_t port, QByteArray password)
Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
{
QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
QNetworkConfiguration *cfg = new QNetworkConfiguration;
QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
ncm->updateConfigurations();
*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;
while ( !stop )

+ 1
- 1
server.h View File

@@ -30,7 +30,7 @@ Q_OBJECT

public:
Server ( std::vector<Socket*> *sockets_vector );
Server ( uint16_t port, QByteArray password );
Server ( uint16_t port, QByteArray ssid, QByteArray password );
~Server();

void discoverSockets();

+ 14
- 0
socket.cpp View File

@@ -127,6 +127,20 @@ void Socket::toggle()
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 )
{
QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);

+ 2
- 0
socket.h View File

@@ -41,6 +41,8 @@ public:
Socket ( QHostAddress, QByteArray ); // from discovery packet
~Socket();
void toggle();
void powerOff();
void powerOn();
void discover();
void tableData();
void changeSocketName ( QString newName );

Loading…
Cancel
Save