Restore ability to set a different ssid.

Add on and off commands.
master
Andrius Štikonas 8 years ago
parent df5cc31355
commit de16fea254
  1. 12
      consolereader.cpp
  2. 2
      s20.pro
  3. 9
      server.cpp
  4. 2
      server.h
  5. 14
      socket.cpp
  6. 2
      socket.h

@ -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,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

@ -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 )

@ -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();

@ -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);

@ -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