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()
43 43
         case 'a':
44 44
         {
45 45
             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;
46
-            std::string password;
46
+            std::string ssid, password;
47
+            std::cout << "Wireless name (\"c\" for current wifi): ";
48
+            std::cin >> ssid;
47 49
             std::cout << "Password: ";
48 50
             std::cin >> password;
49
-            Server *server = new Server(48899, QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899
51
+            Server *server = new Server(48899, QByteArray::fromStdString(ssid), QByteArray::fromStdString(password)); // HF-LPB100 chip can be controlled over port 48899
50 52
             break;
51 53
         }
52 54
         case 'A':
@@ -75,6 +77,12 @@ void ConsoleReader::run()
75 77
         case 'p':
76 78
             (*sockets) [number]->toggle();
77 79
             break;
80
+        case 'o':
81
+            if (command == "off")
82
+                (*sockets) [number]->powerOff();
83
+            else if (command == "on")
84
+                (*sockets) [number]->powerOn();
85
+            break;
78 86
         case 'P':
79 87
         {
80 88
             std::string password;

+ 1
- 1
s20.pro View File

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

+ 7
- 2
server.cpp View File

@@ -40,14 +40,19 @@ Server::Server ( std::vector<Socket*> *sockets_vector )
40 40
     start();
41 41
 }
42 42
 
43
-Server::Server(uint16_t port, QByteArray password)
43
+Server::Server(uint16_t port, QByteArray ssid, QByteArray password)
44 44
 {
45 45
     QNetworkConfiguration *cfgInitial = new QNetworkConfiguration;
46 46
     QNetworkConfiguration *cfg = new QNetworkConfiguration;
47 47
     QNetworkConfigurationManager *ncm = new QNetworkConfigurationManager;
48 48
     ncm->updateConfigurations();
49 49
     *cfgInitial = ncm->defaultConfiguration();
50
-    QByteArray ssid = cfgInitial->name().toLocal8Bit();
50
+
51
+    if (ssid == "c")
52
+    {
53
+        ssid = cfgInitial->name().toLocal8Bit();
54
+        qDebug() << "SSID unspecified, using current network: " << ssid;
55
+    }
51 56
 
52 57
     bool stop = false;
53 58
     while ( !stop )

+ 1
- 1
server.h View File

@@ -30,7 +30,7 @@ Q_OBJECT
30 30
 
31 31
 public:
32 32
     Server ( std::vector<Socket*> *sockets_vector );
33
-    Server ( uint16_t port, QByteArray password );
33
+    Server ( uint16_t port, QByteArray ssid, QByteArray password );
34 34
     ~Server();
35 35
 
36 36
     void discoverSockets();

+ 14
- 0
socket.cpp View File

@@ -127,6 +127,20 @@ void Socket::toggle()
127 127
     sendDatagram ( powered ? PowerOff : PowerOn );
128 128
 }
129 129
 
130
+void Socket::powerOff()
131
+{
132
+    if (powered)
133
+        sendDatagram ( PowerOff );
134
+    Q_EMIT stateChanged();
135
+}
136
+
137
+void Socket::powerOn()
138
+{
139
+    if (!powered)
140
+        sendDatagram ( PowerOn );
141
+    Q_EMIT stateChanged();
142
+}
143
+
130 144
 void Socket::changeSocketName ( QString newName )
131 145
 {
132 146
     QByteArray name = newName.toLatin1().leftJustified(16, ' ', true);

+ 2
- 0
socket.h View File

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

Loading…
Cancel
Save