CayenneMQTT - SteveCossy/IOT GitHub Wiki

Scripts that get data from an MQTT broker (such as Cayenne or Mosquitto)
... and into:

  • backup csv files.
  • on to a map if asked.

The essential files for this part of the project are in the CayenneMQTT folder. This is an original folder and once contained all required scripts. Some have been moved to the LoRa Read page.

First we need to generate a config file:

This needs to start with four keys:

Three Cayenne specific settings come from the Cayenne Project Configure settings
  • MQTT Username - Required to open this Project
  • MQTT Password - Likewise - open Project
  • Client ID - Required to access specific data once you have already opened the Project
  • Unique Client ID - This is a standard MQTT requirement. Each process that wants to open the project must have a unique Client ID.
    The libraries provided by Cayenne don't have any obvious way to handle this. Perhaps the ClientID used by the library is made up on the fly. (Perhaps my software should do this ... hummm ) Otherwise only one process could open an MQTT source at a time. In our case we need two - one to publish MQTT to Cayenne, second to subscribe to Cayenne to get the data back out.
Click the Gear icon on the project header, then select Configure (Right-Click image and open in a new tab to view.)
  • MkAuthSettings.py
    Create a config file, using the TOML library.
    Currently this code puts the code into a static file - this needs thinking and fixing
  • RdAuthSettings.py
    Dumps the current configuration settings, to check you've created it properly

Read our data from a sensor to Cayenne:

  • This is covered in detail on the LoRa Read page.

Python code to get the information from Cayenne, into local files:

  • cayMQTT_to_csv.html
    Uses generic [Paho-MQTT](https://pypi.org/project/paho-mqtt/) libraries to get information from Cayenne. The generic libraries are used because this is a very simple operation so I want to retain control over it, without introducing the far more multi-purpose Cayenne specific libraries. It is envisaged that at some stage a different MQTT broker might be used.
    • Reads MQTT data from Cayenne
    • Writes csv file
  • csv2json-CayMQTT.py
    Converts csv file into a geoJason format. Creates Time variable, which should be done later.

Both these sets of scripts, and others, use various text file (TOML or csv) to store data externally. These files are described here.

HTML and Javascript code to get the information from local files onto a webpage:

This code is a combination and client side and server side scripts.

  • index.html Contains HTML and Javascript to display the geoJson information nicely.
    • Reads geoJson file
    • Provides web page
    • Uses: style.css to be stylish
  • Supporting files (subfolders and file required in **index.html** folder)
    • scripts
    • styles
    • favicon.ico Icon that appears in the browser tab

    Other files

    • CayenneProjectConfigure.png Documentation used above and on another Wiki page.
    • README.rst Readme file for this folder.

    Most of these ones will be removed...

    • Cicadacom LoRaRssi 1910.txt
    • FixRandoms.sh
    • GPS RF Tx Lat Lon JKL 1910.txt
    • RSSILatLong.geojson
    • RestartCSV.sh
    • Serial_to_MQTT.py
    • csv2json-CayMQTT-hm.py
    • references.html - list of URLs used to build the above
    • requirements.2019-11-25 - superset of libraries required to be imported using pip3
    • cayMQTT_to_csv.py - Old file, to be deleted at some point, after checking
  • ⚠️ **GitHub.com Fallback** ⚠️