Giter Site home page Giter Site logo

prisms-wifi-sensor's Introduction

Utah Modified Dylos Code

This code reads air quality data from the Dylos serial port, temperature and humidity from the SHT21 sensor, and writes information to an LCD screen. The only mandatory sensor is the Dylos -- all other sensors will gracefully fail if not connected. There are a few software sensors as well: local ping (pings the gateway), remote ping (pings our server), and wireless (captures wireless stats).

It creates a CoAP server with the endpoint air-quality.

GET coap://<device>/air_quality

In the request payload, two integers need to be included. These integers should be the number of data points to acknowledge and how many data point to send. See utils/coap_client.py as an example. The result of this request is a list of data samples, in the following format:

[
    [associated, data_rate, humidity, invalid_misc, large, link_quality, local_ping_errors, local_ping_latency, local_ping_packet_loss, local_ping_total, noise_level, remote_ping_errors, remote_ping_latency, remote_ping_packet_loss, remote_ping_total, rx_invalid_crypt, rx_invalid_frag, rx_invalid_nwid, sampletime, sequence, signal_level, small, temperature, tx_retires]
    ...
]

It also supports the .well-known/core endpoint for resource discovery.

GET coap://<device>/.well-known/core

This returns all of the resources available from the Dylos sensor. For example:

</air_quality>;</name=monitorX>;</type=dylos-2>;

shows the air_quality endpoint, the name of the sensor (hostname) and type of sensor.

The CoAP server also binds to the CoAP multicast address (224.0.1.187), which means it response to multicast requests. This works well for discovery.

The code has been tested using Python 3.5. To run,

python3 main.py

This starts the CoAP server and starts reading from the sensors.

prisms-wifi-sensor's People

Contributors

philipbl avatar pavithracp avatar

Watchers

James Cloos avatar  avatar Randy K Madsen avatar Rob avatar Kyeong Min avatar Neal Patwari avatar  avatar  avatar Sumon Chattopadhyay avatar

prisms-wifi-sensor's Issues

Improve metadata

The following pieces of information would help to have in the metadata:

  • Internal IP address
  • Software version

Update README

README describes the old method (CoAP). We need a description of MQTT.

Log uncaught exceptions

Currently uncaught exceptions aren't logged in the file. This gives us an incomplete picture of what is going on with the sensor. We need to set up logging to catch all exceptions.

Crash while getting wireless stats

While trying to get wireless stats, a crash occurs.

2017-12-18 00:00:14,616:Thread-1:ERROR:sensors.wireless:Exception occurred while getting wireless stats
Traceback (most recent call last):
  File "/root/dylos/sensors/wireless.py", line 48, in read
    stats = lines[0].split()
IndexError: list index out of range
2017-12-18 00:00:14,764:Thread-1:ERROR:sensors.wireless:Exception occurred while running iwconfig
Traceback (most recent call last):
  File "/root/dylos/sensors/wireless.py", line 68, in read
    timeout=5)
  File "/root/pyenv/versions/3.5.2/lib/python3.5/subprocess.py", line 626, in check_output
    **kwargs).stdout
  File "/root/pyenv/versions/3.5.2/lib/python3.5/subprocess.py", line 708, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command 'iwconfig ra0' returned non-zero exit status 237

We handle the crash, but the code that tries to reconnect to WiFi is unable to run. With this crash and if the sensor is disconnected to WiFi, it will never try to reconnect to WiFi.

Add watchdog timer

Under certain conditions, automatically restart the sensor. The two conditions that I can think of right now are no data from the Dylos sensor and unable to connect to WiFi.

Unable to connect to MQTT broker after restart

After restarting the sensor (because of another issue) the sensor is unable to connect to the MQTT broker. For many hours, the sensor keeps on trying but never succeeds.

2018-01-06 06:07:02,208:MainThread:ERROR:__main__:Connection failure...trying to reconnect...
Traceback (most recent call last):
  File "main.py", line 323, in main
    client.connect(mqtt_cfg['server'], mqtt_cfg['port'])
  File "/root/pyenv/versions/3.5.2/envs/dylos/lib/python3.5/site-packages/paho/mqtt/client.py", line 768, in connect
    return self.reconnect()
  File "/root/pyenv/versions/3.5.2/envs/dylos/lib/python3.5/site-packages/paho/mqtt/client.py", line 895, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/root/pyenv/versions/3.5.2/lib/python3.5/socket.py", line 693, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/root/pyenv/versions/3.5.2/lib/python3.5/socket.py", line 732, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

At the same time, the sensor is unable to ping the database:

2018-01-06 06:09:47,891:Thread-4:WARNING:sensors.ping:Ping error: ping: unknown host p1db-prisms-p1.bmi.utah.edu

or local network:

2018-01-06 06:09:51,549:Thread-3:WARNING:sensors.ping:Ping error: ping: unknown host gateway.local

For some reason the wireless sensor is not running. Wireless statistics are not getting pushed onto the queue:

2018-01-06 06:08:02,777:Thread-1:DEBUG:__main__:Pushing {'temperature': (69.35, '<C2><B0>F'), 'local_ping_errors': (11, 'num'), 'remote_ping_errors': (5, 'num'), 'sampletime': (1515218882.6456475, 's'), 'large': (91, 'pm'), 'small': (1185, 'pm'), 'remote_ping_packet_loss': (0, 'num'), 'sequence': (1, 'sequence'), 'remote_ping_latency': (0, 'ms'), 'local_ping_total': (11, 'num'), 'humidity': (38.12, '%'), 'local_ping_latency': (0, 'ms'), 'remote_ping_total': (5, 'num'), 'local_ping_packet_loss': (0, 'num'), 'queue_length': (9850, 'num')} into queue

The clock is up to date which makes me think it is connected to the Internet.

Sensor offline after disconnect from MQTT broker

When a sensor gets disconnected from the MQTT broker, it becomes offline. When it comes back online, sometimes the status does not change to online.

This could be a timing issue between the broker sending the offline last will and the sensor sending the online message.

Read-only File System

Sometimes a sensor stops working and when sshing, it says

-bash: test.txt: Read-only file system

This seems like a corrupt file system. Is there anything we can do to fix this or at least get notified when it happens?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.