Instrument Neutral Distributed Interface INDI 2.2.5
pegasus_wifi.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Pegasus Astro WiFi settings
3
4 Copyright (C) 2026 Dominik Merkel
5
6 Shared by the drivers of Pegasus Astro devices with the common WiFi command set.
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21*******************************************************************************/
22
23#include "pegasus_wifi.h"
24
25#include "defaultdevice.h"
26#include "eventloop.h"
27#include "indicom.h"
28#include "indilogger.h"
29
30#include <algorithm>
31#include <cstring>
32#include <sys/select.h>
33#include <termios.h>
34#include <unistd.h>
35#include <vector>
36
37namespace PegasusAstro
38{
39
40#define WIFI_LOG(level, ...) DEBUGFDEVICE(m_Device->getDeviceName(), level, __VA_ARGS__)
41
45
46void WiFi::initProperties(const char *tab, LoadConfig loadConfig, SaveConfig saveConfig)
47{
48 m_LoadConfig = std::move(loadConfig);
49 m_SaveConfig = std::move(saveConfig);
50 const char *dev = m_Device->getDeviceName();
51
52 // Hotspot on/off (A? / AE:x)
53 HotspotSP[0].fill("HOTSPOT_ENABLE", "Enable", ISS_OFF);
54 HotspotSP[1].fill("HOTSPOT_DISABLE", "Disable", ISS_ON);
55 HotspotSP.fill(dev, "HOTSPOT_STATUS", "Hotspot", tab, IP_RW, ISR_1OFMANY, 60, IPS_IDLE);
56
57 // Hotspot name and password (AL / AN: / AP:). The password is also the TCP and web login.
58 HotspotTP[0].fill("HOTSPOT_SSID", "SSID", "");
59 HotspotTP[1].fill("HOTSPOT_PASSWORD", "Password", "");
60 HotspotTP.fill(dev, "HOTSPOT_CREDENTIALS", "Hotspot Credentials", tab, IP_RW, 60, IPS_IDLE);
61
62 // Hotspot channel (AC / AC:n)
63 ChannelNP[0].fill("WIFI_CHANNEL_VALUE", "Channel (1-11)", "%.0f", 1, 11, 1, 11);
64 ChannelNP.fill(dev, "WIFI_CHANNEL", "WiFi Channel", tab, IP_RW, 60, IPS_IDLE);
65
66 // Network the device is connected to as a client (WA)
67 ConnectionTP[0].fill("CURRENT_WIFI", "Connection", "");
68 ConnectionTP.fill(dev, "CURRENT_WIFI", "Current WiFi", tab, IP_RO, 60, IPS_IDLE);
69
70 // Network scan (WS)
71 ScanSP[0].fill("WIFI_SCAN", "Scan", ISS_OFF);
72 ScanSP.fill(dev, "WIFI_SCAN", "Scan Networks", tab, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
73 ScanTP[0].fill("WIFI_SCAN_RESULTS", "Networks", "");
74 ScanTP.fill(dev, "WIFI_SCAN_RESULTS", "Scan Results", tab, IP_RO, 60, IPS_IDLE);
75
76 // WiFi client (WN: / WP:)
77 NetworkTP[0].fill("WIFI_SSID", "SSID", "");
78 NetworkTP[1].fill("WIFI_PASSWORD", "Password", "");
79 NetworkTP.fill(dev, "WIFI_CONNECT_CREDS", "WiFi Credentials", tab, IP_RW, 60, IPS_IDLE);
80 ConnectSP[0].fill("WIFI_CONNECT", "Connect", ISS_OFF);
81 ConnectSP.fill(dev, "WIFI_CONNECT", "Connect to WiFi", tab, IP_RW, ISR_ATMOST1, 60, IPS_IDLE);
82
83 // Login on the TCP command socket: the hotspot password
84 PasswordTP[0].fill("TCP_PASSWORD_VALUE", "Password", DEFAULT_PASSWORD);
85 PasswordTP.fill(dev, "TCP_PASSWORD", "TCP Password", CONNECTION_TAB, IP_RW, 60, IPS_IDLE);
86}
87
89{
90 m_Device->defineProperty(PasswordTP);
91 if (!m_PasswordLoaded)
92 {
93 m_PasswordLoaded = true;
94 m_LoadConfig(PasswordTP.getName());
95 }
96}
97
98void WiFi::updateProperties(bool connected, int portFD)
99{
100 if (connected)
101 {
102 m_PortFD = portFD;
103 m_Device->defineProperty(HotspotSP);
104 m_Device->defineProperty(HotspotTP);
105 m_Device->defineProperty(ChannelNP);
106 m_Device->defineProperty(ConnectionTP);
107 m_Device->defineProperty(ScanSP);
108 m_Device->defineProperty(ScanTP);
109 m_Device->defineProperty(NetworkTP);
110 m_Device->defineProperty(ConnectSP);
111
112 readHotspotStatus();
113 readHotspotCredentials();
114 readChannel();
115 readConnection();
116 }
117 else
118 {
119 m_Device->deleteProperty(HotspotSP);
120 m_Device->deleteProperty(HotspotTP);
121 m_Device->deleteProperty(ChannelNP);
122 m_Device->deleteProperty(ConnectionTP);
123 m_Device->deleteProperty(ScanSP);
124 m_Device->deleteProperty(ScanTP);
125 m_Device->deleteProperty(NetworkTP);
126 m_Device->deleteProperty(ConnectSP);
127 m_PortFD = -1;
128 }
129}
130
131bool WiFi::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
132{
133 if (dev == nullptr || strcmp(dev, m_Device->getDeviceName()) != 0)
134 return false;
135
136 if (HotspotSP.isNameMatch(name))
137 {
138 const char *onSwitch = IUFindOnSwitchName(states, names, n);
139 const bool enable = onSwitch != nullptr && HotspotSP[0].isNameMatch(onSwitch);
140 char cmd[LEN] = {0}, res[LEN] = {0};
141 snprintf(cmd, LEN, "AE:%d", enable ? 1 : 0);
142 // The FocusCube 3 and Falcon V2 answer 1; the FlatMaster Neo answer is not documented. Only 0 is
143 // a failure, and the state is read back below either way.
144 if (sendCommand(cmd, res, LEN) && strcmp(res, "0") != 0)
145 {
146 readHotspotStatus();
147 if (enable && strcmp(HotspotTP[1].getText(), DEFAULT_PASSWORD) == 0)
149 "The hotspot uses the factory password. Change it, since anyone in range can control the device.");
150 }
151 else
152 {
153 WIFI_LOG(INDI::Logger::DBG_ERROR, "Switching the hotspot failed: %s", res);
154 HotspotSP.setState(IPS_ALERT);
155 HotspotSP.apply();
156 }
157 return true;
158 }
159
160 if (ScanSP.isNameMatch(name))
161 {
162 ScanSP.reset();
163 ScanSP.setState(scan() ? IPS_OK : IPS_ALERT);
164 ScanSP.apply();
165 return true;
166 }
167
168 if (ConnectSP.isNameMatch(name))
169 {
170 ConnectSP.reset();
171 ConnectSP.setState(connectToNetwork(NetworkTP[0].getText(), NetworkTP[1].getText()) ? IPS_OK : IPS_ALERT);
172 ConnectSP.apply();
173 return true;
174 }
175
176 return false;
177}
178
179bool WiFi::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
180{
181 if (dev == nullptr || strcmp(dev, m_Device->getDeviceName()) != 0)
182 return false;
183
184 if (PasswordTP.isNameMatch(name))
185 {
186 PasswordTP.update(texts, names, n);
187 PasswordTP.setState(IPS_OK);
188 PasswordTP.apply();
189 m_SaveConfig(PasswordTP);
190 return true;
191 }
192
193 if (HotspotTP.isNameMatch(name))
194 {
195 HotspotTP.update(texts, names, n);
196 const std::string ssid = HotspotTP[0].getText(), password = HotspotTP[1].getText();
197 const bool set = setHotspotCredentials(ssid.c_str(), password.c_str());
198 // Only 0 counts as a failure of AN:/AP:, so the device may not have taken the change.
199 // Read back what it stores before saving the password as the TCP login.
200 if (!readHotspotCredentials() || !set)
201 return true;
202
203 // The hotspot password is also the login of the TCP socket and the web dashboard.
204 PasswordTP[0].setText(HotspotTP[1].getText());
205 PasswordTP.apply();
206 m_SaveConfig(PasswordTP);
207 if (ssid == HotspotTP[0].getText() && password == HotspotTP[1].getText())
209 "Hotspot credentials set. The password is also the login for TCP and the web dashboard.");
210 else
211 {
212 HotspotTP.setState(IPS_ALERT);
213 HotspotTP.apply();
215 "The device did not take the new hotspot credentials. The TCP password is set to the password it reports.");
216 }
217 return true;
218 }
219
220 if (NetworkTP.isNameMatch(name))
221 {
222 // The credentials are sent with "Connect to WiFi".
223 NetworkTP.update(texts, names, n);
224 NetworkTP.setState(IPS_OK);
225 NetworkTP.apply();
226 return true;
227 }
228
229 return false;
230}
231
232bool WiFi::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
233{
234 if (dev == nullptr || strcmp(dev, m_Device->getDeviceName()) != 0)
235 return false;
236
237 if (ChannelNP.isNameMatch(name))
238 {
239 if (!ChannelNP.update(values, names, n))
240 {
241 ChannelNP.setState(IPS_ALERT);
242 ChannelNP.apply();
243 return true;
244 }
245
246 const int channel = static_cast<int>(ChannelNP[0].getValue());
247 char cmd[LEN] = {0}, res[LEN] = {0};
248 snprintf(cmd, LEN, "AC:%d", channel);
249 // The FocusCube 3 and Falcon V2 answer with the channel, the FlatMaster Neo with 1; 0 is a failure.
250 if (!sendCommand(cmd, res, LEN) || strcmp(res, "0") == 0)
251 WIFI_LOG(INDI::Logger::DBG_ERROR, "Setting the WiFi channel failed: %s", res);
252 readChannel();
253 return true;
254 }
255
256 return false;
257}
258
260{
261 PasswordTP.save(fp);
262}
263
264bool WiFi::login(int portFD)
265{
266 // Send the hotspot password first. The Falcon V2 replies AUTHOK, or closes the connection on a
267 // wrong password; a closed connection is the expected answer then, so no read error is logged.
268 // The FocusCube 3 (firmware 2.0) asks for no password and answers the first line with ">>".
269 m_PortFD = portFD;
270 WIFI_LOG(INDI::Logger::DBG_DEBUG, "%s", "CMD <password>");
271 char cmd[LEN] = {0}, res[LEN] = {0};
272 snprintf(cmd, LEN, "%s\r\n", PasswordTP[0].getText());
273 int nbytes = 0;
274 if (tty_write_string(portFD, cmd, &nbytes) == TTY_OK &&
275 tty_nread_section(portFD, res, LEN - 1, '\n', 3, &nbytes) == TTY_OK)
276 {
277 if (strncmp(res, "AUTHOK", 6) == 0)
278 {
279 WIFI_LOG(INDI::Logger::DBG_DEBUG, "%s", "Logged in on the TCP command socket.");
280 return true;
281 }
282 if (strncmp(res, ">>", 2) == 0)
283 {
285 "The device accepts TCP commands without a password, so anyone on the network can control it.");
286 return true;
287 }
288 }
289
291 "TCP login failed. Check the TCP Password on the Connection tab; it is the hotspot password.");
292 return false;
293}
294
295bool WiFi::sendCommand(const char *cmd, char *res, int len, int timeout, bool secret)
296{
297 // Commands end with CR LF (the FocusCube 3 needs the CR over TCP); replies are one line.
298 WIFI_LOG(INDI::Logger::DBG_DEBUG, "CMD <%s>", secret ? "<password>" : cmd);
299
300 char command[LEN] = {0};
301 snprintf(command, LEN, "%s\r\n", cmd);
302 int nbytes = 0;
303 drain(m_PortFD);
304 int rc = tty_write_string(m_PortFD, command, &nbytes);
305 if (rc == TTY_OK)
306 rc = tty_nread_section(m_PortFD, res, len - 1, '\n', timeout, &nbytes);
307 if (rc != TTY_OK)
308 {
309 char error[MAXRBUF] = {0};
310 tty_error_msg(rc, error, MAXRBUF);
311 WIFI_LOG(INDI::Logger::DBG_ERROR, "WiFi command error: %s", error);
312 return false;
313 }
314
315 res[nbytes] = '\0';
316 while (nbytes > 0 && (res[nbytes - 1] == '\n' || res[nbytes - 1] == '\r'))
317 res[--nbytes] = '\0';
318
319 // AL carries the hotspot password, and the FlatMaster Neo echoes WP:<password>.
320 WIFI_LOG(INDI::Logger::DBG_DEBUG, "RES <%s>", strcmp(cmd, "AL") == 0 ? "<ssid>:<password>" : secret ? "<hidden>" : res);
321 return true;
322}
323
324void WiFi::drain(int portFD)
325{
326 tcflush(portFD, TCIOFLUSH);
327
328 char buffer[LEN];
329 while (true)
330 {
331 fd_set set;
332 FD_ZERO(&set);
333 FD_SET(portFD, &set);
334 struct timeval timeout = {0, 0};
335 if (select(portFD + 1, &set, nullptr, nullptr, &timeout) <= 0 || read(portFD, buffer, sizeof(buffer)) <= 0)
336 break;
337 }
338}
339
341{
342 if (m_PortFD >= 0)
343 readConnection();
344}
345
346bool WiFi::readHotspotStatus()
347{
348 char res[LEN] = {0};
349 if (!sendCommand("A?", res, LEN))
350 return false;
351
352 const bool on = strcmp(res, "1") == 0;
353 HotspotSP[0].setState(on ? ISS_ON : ISS_OFF);
354 HotspotSP[1].setState(on ? ISS_OFF : ISS_ON);
355 HotspotSP.setState(IPS_OK);
356 HotspotSP.apply();
357 return true;
358}
359
360bool WiFi::readHotspotCredentials()
361{
362 // Reply: <ssid>:<password>
363 char res[LEN] = {0};
364 const char *separator = nullptr;
365 if (!sendCommand("AL", res, LEN) || (separator = strchr(res, ':')) == nullptr)
366 {
367 HotspotTP.setState(IPS_ALERT);
368 HotspotTP.apply();
369 return false;
370 }
371
372 HotspotTP[0].setText(std::string(res, separator - res).c_str());
373 HotspotTP[1].setText(separator + 1);
374 HotspotTP.setState(IPS_OK);
375 HotspotTP.apply();
376 return true;
377}
378
379bool WiFi::readChannel()
380{
381 char res[LEN] = {0};
382 const int channel = sendCommand("AC", res, LEN) ? atoi(res) : 0;
383 if (channel < 1 || channel > 11)
384 {
385 ChannelNP.setState(IPS_ALERT);
386 ChannelNP.apply();
387 return false;
388 }
389
390 ChannelNP[0].setValue(channel);
391 ChannelNP.setState(IPS_OK);
392 ChannelNP.apply();
393 return true;
394}
395
396bool WiFi::readConnection()
397{
398 // Reply: 0 while not connected, otherwise <ssid>,<ip address>,<signal %>,<security>.
399 char res[LEN] = {0};
400 if (!sendCommand("WA", res, LEN))
401 return false;
402
403 m_Connected = strcmp(res, "0") != 0;
404 std::string text = m_Connected ? res : "Not connected";
405 if (m_Connected)
406 {
407 // The SSID may contain commas, so take the other fields from the end.
408 const std::string reply(res);
409 const size_t security = reply.rfind(',');
410 const size_t signal = security == std::string::npos || security == 0 ? std::string::npos : reply.rfind(',', security - 1);
411 const size_t address = signal == std::string::npos || signal == 0 ? std::string::npos : reply.rfind(',', signal - 1);
412 if (address != std::string::npos && address > 0)
413 text = reply.substr(0, address) + " (" + reply.substr(address + 1, signal - address - 1) + "), signal " +
414 reply.substr(signal + 1, security - signal - 1) + "%";
415 }
416
417 // This runs on every poll, so tell the clients only about a change.
418 if (text != ConnectionTP[0].getText() || ConnectionTP.getState() != IPS_OK)
419 {
420 ConnectionTP[0].setText(text.c_str());
421 ConnectionTP.setState(IPS_OK);
422 ConnectionTP.apply();
423 }
424 return true;
425}
426
427bool WiFi::scan()
428{
429 // The radio is only on with the hotspot enabled or a client connection.
430 if (HotspotSP[1].getState() == ISS_ON && !m_Connected)
431 {
433 "The scan needs the WiFi radio. Enable the hotspot or connect to a WiFi network first.");
434 return false;
435 }
436
437 WIFI_LOG(INDI::Logger::DBG_SESSION, "%s", "Scanning for WiFi networks...");
438 char res[SCAN_LEN] = {0};
439 // Right after the radio is switched on, the first scans can come back empty.
440 for (int i = 0; i < SCAN_RETRIES; i++)
441 {
442 if (!sendCommand("WS", res, SCAN_LEN, SCAN_TIMEOUT))
443 return false;
444 if (strcmp(res, "0") != 0)
445 break;
446 if (i + 1 < SCAN_RETRIES)
447 usleep(SCAN_RETRY_DELAY_US);
448 }
449
450 ScanTP[0].setText(strcmp(res, "0") == 0 ? "No networks found" : formatScan(res).c_str());
451 ScanTP.setState(IPS_OK);
452 ScanTP.apply();
453 return true;
454}
455
456std::string WiFi::formatScan(const char *reply)
457{
458 // Reply: <ssid>,<signal %>,<security>: per access point. List each SSID once with its best signal.
459 std::vector<std::pair<std::string, int>> networks;
460 std::string entries(reply);
461 size_t start = 0;
462 while (start < entries.size())
463 {
464 size_t end = entries.find(':', start);
465 if (end == std::string::npos)
466 end = entries.size();
467 const std::string entry = entries.substr(start, end - start);
468 start = end + 1;
469
470 // The SSID may contain commas, so take signal and security from the end.
471 const size_t security = entry.rfind(',');
472 const size_t signal = security == std::string::npos || security == 0 ? std::string::npos : entry.rfind(',', security - 1);
473 if (signal == std::string::npos || signal == 0)
474 continue;
475
476 const std::string ssid = entry.substr(0, signal);
477 const int quality = atoi(entry.substr(signal + 1, security - signal - 1).c_str());
478 auto known = std::find_if(networks.begin(), networks.end(), [&](const auto & network)
479 {
480 return network.first == ssid;
481 });
482 if (known == networks.end())
483 networks.emplace_back(ssid, quality);
484 else
485 known->second = std::max(known->second, quality);
486 }
487
488 std::stable_sort(networks.begin(), networks.end(), [](const auto & a, const auto & b)
489 {
490 return a.second > b.second;
491 });
492
493 std::string text;
494 for (const auto &network : networks)
495 text += (text.empty() ? "" : ", ") + network.first + " (" + std::to_string(network.second) + "%)";
496 return text.empty() ? std::string(reply) : text;
497}
498
499bool WiFi::validText(const char *text, size_t maxLength)
500{
501 // A newline would end the command early.
502 return text != nullptr && text[0] != '\0' && strlen(text) <= maxLength && strpbrk(text, "\r\n") == nullptr;
503}
504
505bool WiFi::setHotspotCredentials(const char *ssid, const char *password)
506{
507 if (!validText(ssid, 32) || !validText(password, 63) || strlen(password) < 8)
508 {
510 "Hotspot SSID must have 1 to 32 characters and the password 8 to 63 characters.");
511 return false;
512 }
513
514 // The FlatMaster Neo, FocusCube 3 and Falcon V2 answer 1; only 0 is a failure. The caller reads
515 // the credentials back, since a device may not have taken them.
516 char cmd[LEN] = {0}, res[LEN] = {0};
517 snprintf(cmd, LEN, "AN:%s", ssid);
518 if (!sendCommand(cmd, res, LEN) || strcmp(res, "0") == 0)
519 {
520 WIFI_LOG(INDI::Logger::DBG_ERROR, "Setting the hotspot SSID failed: %s", res);
521 return false;
522 }
523
524 // The devices answer 1, but a firmware that echoes the password as for WP: must not log it.
525 snprintf(cmd, LEN, "AP:%s", password);
526 if (!sendCommand(cmd, res, LEN, 3, true) || strcmp(res, "0") == 0)
527 {
528 WIFI_LOG(INDI::Logger::DBG_ERROR, "%s", "Setting the hotspot password failed.");
529 return false;
530 }
531
532 return true;
533}
534
535bool WiFi::connectToNetwork(const char *ssid, const char *password)
536{
537 // An open network has no password; where allowed, the device gets a placeholder instead.
538 const bool open = m_AllowOpenNetworks && password != nullptr && password[0] == '\0';
539 if (!validText(ssid, 32) || (!open && (!validText(password, 63) || strlen(password) < 8)))
540 {
541 WIFI_LOG(INDI::Logger::DBG_ERROR, "%s", m_AllowOpenNetworks ?
542 "Enter the WiFi SSID (1 to 32 characters) and password (8 to 63 characters, empty for an open network) first." :
543 "Enter the WiFi SSID (1 to 32 characters) and password (8 to 63 characters) first.");
544 return false;
545 }
546
547 char cmd[LEN] = {0}, res[LEN] = {0};
548 snprintf(cmd, LEN, "WN:%s", ssid);
549 if (!sendCommand(cmd, res, LEN) || strcmp(res, "0") == 0)
550 {
551 WIFI_LOG(INDI::Logger::DBG_ERROR, "Setting the WiFi SSID failed: %s", res);
552 return false;
553 }
554
555 // The FlatMaster Neo echoes WP:<password>, so the reply is not logged.
556 snprintf(cmd, LEN, "WP:%s", open ? OPEN_NETWORK_PASSWORD : password);
557 if (!sendCommand(cmd, res, LEN, 3, true) || strcmp(res, "0") == 0)
558 {
559 WIFI_LOG(INDI::Logger::DBG_ERROR, "%s", "Setting the WiFi password failed.");
560 return false;
561 }
562
563 // The device connects in the background (about 5 seconds) and retries every 10 seconds.
564 WIFI_LOG(INDI::Logger::DBG_SESSION, "Connecting to %s...", ssid);
565 IEAddTimer(CONNECT_CHECK_MS, &WiFi::readConnectionLater, this);
566 return true;
567}
568
569void WiFi::readConnectionLater(void *context)
570{
571 auto wifi = static_cast<WiFi *>(context);
572 if (wifi->m_PortFD < 0 || !wifi->readConnection())
573 return;
574
575 if (wifi->m_Connected)
576 DEBUGFDEVICE(wifi->m_Device->getDeviceName(), INDI::Logger::DBG_SESSION, "WiFi connected: %s.",
577 wifi->ConnectionTP[0].getText());
578 else
579 DEBUGFDEVICE(wifi->m_Device->getDeviceName(), INDI::Logger::DBG_WARNING,
580 "Not connected to %s yet. Check SSID and password; the device keeps trying every 10 seconds.",
581 wifi->NetworkTP[0].getText());
582}
583
584}
hid_device * device
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void updateConnection()
Read the current WiFi connection again, e.g. on every poll. Does nothing while not connected.
void saveConfigItems(FILE *fp)
Save the TCP password; the device stores its WiFi settings itself.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
void ISGetProperties()
Define the TCP password and load it once from the configuration. Call from ISGetProperties.
std::function< void(INDI::Property &)> SaveConfig
void initProperties(const char *tab, LoadConfig loadConfig, SaveConfig saveConfig)
Create the properties: the WiFi settings on tab, the TCP password on the connection tab.
static void drain(int portFD)
Discard pending input. tcflush() only works on a serial port, so over TCP a line end left behind by a...
bool login(int portFD)
Log in on the TCP command socket with the hotspot password.
void updateProperties(bool connected, int portFD)
Define the WiFi properties and read the settings, or delete them on disconnect.
bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
std::function< void(const char *)> LoadConfig
WiFi(INDI::DefaultDevice *device)
const char * CONNECTION_TAB
CONNECTION_TAB Where all device connection settings (serial, usb, ethernet) are defined and controlle...
int IEAddTimer(int millisecs, IE_TCF *fp, void *p)
Register a new single-shot timer function, fp, to be called with ud as argument after ms.
Definition eventloop.c:586
Public interface to INDI's eventloop mechanism.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
@ IP_RO
Definition indiapi.h:182
@ IPS_ALERT
Definition indiapi.h:162
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
@ ISR_1OFMANY
Definition indiapi.h:171
@ ISR_ATMOST1
Definition indiapi.h:172
int tty_write_string(int fd, const char *buf, int *nbytes_written)
Writes a null terminated string to fd.
Definition indicom.c:473
void tty_error_msg(int err_code, char *err_msg, int err_msg_len)
Retrieve the tty error message.
Definition indicom.c:1243
int tty_nread_section(int fd, char *buf, int nsize, char stop_char, int timeout, int *nbytes_read)
read buffer from terminal with a delimiter
Definition indicom.c:759
Implementations for common driver routines.
@ TTY_OK
Definition indicom.h:54
const char * IUFindOnSwitchName(ISState *states, char *names[], int n)
Returns the name of the first ON switch it finds in the supplied arguments.
Definition indidevapi.c:355
#define MAXRBUF
Definition indidriver.c:52
*brief user defined string literal for JSON values *sa std::size_t n
#define DEBUGFDEVICE(device, priority, msg,...)
Definition indilogger.h:61
*brief create JSON pointer *sa reference_tokens end()
json_pointer res
#define WIFI_LOG(level,...)
uint8_t cmd[4]
Definition pwc-ioctl.h:2