1527 if (ioctl(sock, SIOCGIWNAME, &wrq) == 0) { |
1527 if (ioctl(sock, SIOCGIWNAME, &wrq) == 0) { |
1528 syslog(LOG_NOTICE, "IF: %s", wrq.ifr_name); |
1528 syslog(LOG_NOTICE, "IF: %s", wrq.ifr_name); |
1529 } |
1529 } |
1530 |
1530 |
1531 wrq.u.essid.pointer = essid; |
1531 wrq.u.essid.pointer = essid; |
1532 if (ioctl(sock, SIOCGIWESSID, &wrq) == -1) { |
1532 if (ioctl(sock, SIOCGIWESSID, &wrq) != -1) { |
1533 syslog(LOG_NOTICE, "Can't open socket to obtain essid"); |
|
1534 } else { |
|
1535 payload = xstrcat(payload, (char *)",\"ssid\":\""); |
1533 payload = xstrcat(payload, (char *)",\"ssid\":\""); |
1536 payload = xstrcat(payload, wrq.u.essid.pointer); |
1534 payload = xstrcat(payload, wrq.u.essid.pointer); |
1537 payload = xstrcat(payload, (char *)"\""); |
1535 payload = xstrcat(payload, (char *)"\""); |
1538 } |
1536 } |
1539 |
1537 |
1540 memset(&iwstats, 0, sizeof(iwstats)); |
1538 memset(&iwstats, 0, sizeof(iwstats)); |
1541 wrq.u.data.pointer = &iwstats; |
1539 wrq.u.data.pointer = &iwstats; |
1542 wrq.u.data.length = sizeof(struct iw_statistics); |
1540 wrq.u.data.length = sizeof(struct iw_statistics); |
1543 wrq.u.data.flags = 1; |
1541 wrq.u.data.flags = 1; |
1544 if (ioctl(sock, SIOCGIWSTATS, &wrq) == -1) { |
1542 if (ioctl(sock, SIOCGIWSTATS, &wrq) != -1) { |
1545 syslog(LOG_NOTICE, "Can't open socket to obtain iwstats"); |
|
1546 } else { |
|
1547 syslog(LOG_NOTICE, "Signal level is %d %d %d", iwstats.qual.updated & IW_QUAL_DBM, iwstats.qual.level, iwstats.qual.noise); |
1543 syslog(LOG_NOTICE, "Signal level is %d %d %d", iwstats.qual.updated & IW_QUAL_DBM, iwstats.qual.level, iwstats.qual.noise); |
1548 if ((iwstats.qual.updated & (IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID)) == 0) { |
1544 if ((iwstats.qual.updated & (IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID)) == 0) { |
1549 /* iwstats.qual.level is __u8 */ |
1545 /* iwstats.qual.level is __u8 */ |
1550 if (iwstats.qual.updated & IW_QUAL_DBM) { |
1546 if (iwstats.qual.updated & IW_QUAL_DBM) { |
1551 rssi = (iwstats.qual.level > 63) ? iwstats.qual.level - 0x100 : iwstats.qual.level; |
1547 rssi = (iwstats.qual.level > 63) ? iwstats.qual.level - 0x100 : iwstats.qual.level; |
1574 fclose(f); |
1570 fclose(f); |
1575 } |
1571 } |
1576 neterr: |
1572 neterr: |
1577 |
1573 |
1578 payload = xstrcat(payload, (char *)"}}"); |
1574 payload = xstrcat(payload, (char *)"}}"); |
1579 syslog(LOG_NOTICE, payload); |
|
1580 if (birth) { |
1575 if (birth) { |
1581 topic = topic_base((char *)"NBIRTH"); |
1576 topic = topic_base((char *)"NBIRTH"); |
1582 publisher(mosq, topic, payload, true); |
1577 publisher(mosq, topic, payload, true); |
1583 } else { |
1578 } else { |
1584 topic = topic_base((char *)"NDATA"); |
1579 topic = topic_base((char *)"NDATA"); |