Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emon pi develop #38

Merged
merged 18 commits into from Aug 16, 2017
Merged

Emon pi develop #38

merged 18 commits into from Aug 16, 2017

Conversation

TrystanLea
Copy link
Member

@TrystanLea TrystanLea commented Aug 5, 2017

This pull request includes @beaylott's "Thread exception reporting, thread restarting, restart counting..." changes and a native message queue implementation outlined by @pb66 in response to threading issues in the emon-pi variant of emonhub.

Explanation of native message queue

In order to move data between the interfacers in emonhub e.g data received by the JeeLib interfacer and then published by the MQTT interfacer, emonhub has been using a python library called pydispatcher.

I had thought that it was a neat solution, moving data between threads with the ease of use similar to MQTT. However @pb66 highlighted that there was an issue with the implementation, that the intention of one thread per interfacer was not being preserved, the MQTT interfacer in particular was actually running in the RFM2Pi thread!

Paul then described a solution that would remove the need for the external pydispatcher library with a simple native message queue implementation. Here is my attempted summary (with references to the lines of code that implement it):

  1. We start with the main thread (in emonhub.py)

  2. The main thread starts a scan of each interfacer (L143)

  3. The main thread finds a pubchannel on the RFM2Pi interfacer called 'ToEmonCMS' (L149)

  4. The main thread reads and removes one item from the 'ToEmonCMS' queue on the RFM2Pi interfacer. (L155)

  5. The main thread iterates through each interfacer looking for subchannel entries called 'ToEmonCMS' (L158-L162)

  6. The main thread posts a copy of the item read from RFM2Pi into the 'ToEmonCMS' queue on each subscribing interfacer. (L168)

  7. The subscribing interfacer then reads and acts on the queue in its own time and in its own thread.

  8. The main thread then goes on to the next interfacer checking its pubchannel's, repeating steps 4 to 6 above.

A single item is read at a time in order to avoid the case where a runaway interfacer monopolizes the main thread which could block the other interfacers, it also allows for the simple use of pop and append.

The implemented result in this pull request fixes the threading issue that was present in the pydispatcher based implementation while reducing emonhub's dependencies, thanks to @pb66 for the idea and description of how to implement.

@glynhudson glynhudson merged commit dda5227 into emon-pi Aug 16, 2017
@glynhudson glynhudson deleted the emon-pi-develop branch August 16, 2017 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants