Now that we have the client object, we can then either query or insert database records. We initialize the InfluxDBClient with the hostname, port (8086 for the API) and provide it with the database name. We define two constants, one for the InfluxDB Host, which is the Public IP of your Compute Engine instance. We import the InfluxDBClient class at the start of the program code.
Let us understand key points of the code listing above: To run the script in the background and indefinately as a ssh user use nohup python dataloggersensehat.py &. Save the script as ‘dataloggersensehat.py’ and run using python dataloggersensehat.py. Print ("Program stopped by keyboard interrupt by user. # Get the three measurement values from the SenseHat sensors # Array of all arguments passed to script '-rn','-run', type=str, help='Run number', required=False,default=now.strftime("%Y%m%d%H%M")) '-sn','-session', type=str, help='Session', required=True)
'-db','-database', type=str, help='Database name', required=True) Parser = argparse.ArgumentParser(description='Program writes measurements data from SenseHat to specified influx db.') '''This function parses and returns arguments passed in''' # How frequently we will write sensor data from SenseHat to the database. Host = "localhost" #Could also set local ip address # (this could be added to the program args instead of beeing hard coded.)
On Debian/Ubuntu, you can install it with this command: You will need to install the InfluxDB Python module maintained here on github. The measurement name and the run tag could be used to set different sessions during testing etc. Prepare and Write the datalogger python programĪ few command arguments have beeen added to make it possible for a user to specify the database name used, to set a measurement name and a run number. Sudo update-rc.d grafana-server defaults 3. To configure the Grafana server to start at boot time: The default HTTP port is 3000 and default user and psw is admin. This will start the grafana-server process as the grafana user, which was created during the package installation. Do not forget to start the Influxdb service on the Raspberry Pi by running this bash command in the terminal: Please follow the instructions in this article.ī. Installing the Influx database is pretty simple. Install the Influx database on the Raspberry PiĪ. Environmental consultants, building managers, energy auditors, research scientists, and many more professionals all rely on data loggers.
A data logger may be a single-unit, stand-alone device with internal sensors, which fits in the palm of a hand, or it may be a multi-channel data collection instrument equipped with one or more external sensors.ĭata loggers are valuable tools for anyone who wants to continuously monitor conditions without having to be on site. They can be deployed indoors, outdoors, and underwater, and can record data for up to years at a time, unattended. Grafana is an open-source, general purpose dashboard and graph composer, which runs as a web application.ĭata loggers are typically compact, battery-powered devices equipped with an internal microprocessor, data storage, and one or more sensors. In this simple datalogger example, we want to try out the Grafana application. The data stored by our datalogger could also been written to a file as comma separated data and then import that file in excel and made some nice graphs and presentations. Grafana Presenting the datalogger results: That will be discussed in a future article.
You could store the data another place as in the cloud or on an external hard drive or usb stick. In our simple datalogger example, the data is stored on the SD card hence make sure you use a good quality type of card as it will be written to many times. InfluxDB also offers a SQL-like query language for interacting with data.
It is possible to conserve space on your machine by configuring InfluxDB to keep data for a defined length of time, automatically expiring and deleting any unwanted data from the system. InfluxDB is a custom high performance datastore written specifically for timestamped data, including DevOps monitoring, application metrics, IoT sensor data, & real-time analytics.
InfluxDB is a Time Series Database built from the ground up to handle high write & query loads. We have decided to use the Influxdb database to organize and store our data. Our simple datalogger needs some kind of place to organize and store the datalogger measurement samples. We will logg data from the Sense Hat temperature, humidity and the barometric pressure sensors.