Skip to content

Commit

Permalink
add support for am2320 sensor (netdata#7024)
Browse files Browse the repository at this point in the history
* add support for am2320 sensor

add support for am2320 temperature and humidity sensor

* Rename readme.md to README.md

* updated README.md to include proper sections

updated README.md to include proper sections

* readme updated and file name corrected

readme updated with missing formatting and information. AM2320.chart.py
filename corrected.

* changed simple service import

chnaged simple service import location

* updated README.md to remove the reference of moving the script file.

* requested changes

- Moved header from README.md to am2320.chart.py
- Added Alarm for am2320 to health.d
- Changed exception to value error in am2320.chart.py

* typo

changed mae to make in comment

* Add title and icon for AM2320 Sensor

Add title and icon for AM2320 Sensor

* typo corrected

changed Save to save

* added I2C group to installer

Added netdata to the I2C group during install or update.
Removed instruction to add netdate to I2C group from README.md

* change tab to spaces

change tab to spaces
  • Loading branch information
tommybuck authored and thiagoftsm committed Oct 22, 2019
1 parent 74f9ccd commit 3fdf18d
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 1 deletion.
1 change: 1 addition & 0 deletions collectors/python.d.plugin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dist_pythonconfig_DATA = \
$(NULL)

include adaptec_raid/Makefile.inc
include am2320/Makefile.inc
include apache/Makefile.inc
include beanstalk/Makefile.inc
include bind_rndc/Makefile.inc
Expand Down
8 changes: 8 additions & 0 deletions collectors/python.d.plugin/am2320/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: GPL-3.0-or-later

# install these files
dist_python_DATA += am2320/am2320.chart.py
dist_pythonconfig_DATA += am2320/am2320.conf

# do not install these files, but include them in the distribution
dist_noinst_DATA += am2320/README.md am2320/Makefile.inc
37 changes: 37 additions & 0 deletions collectors/python.d.plugin/am2320/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# AM2320
This module will display a graph of the temperture and humity from a AM2320 sensor.

**Requirements:**
- Adafruit Circuit Python AM2320 library
- Adafruit AM2320 I2C sensor
- Python 3 (Adafruit libraries are not Python 2.x compatible)


It produces the following charts:
1. **Temperature**
2. **Humidity**

## configuration

Raspbery Pi Instructions:

Hardware install:
Connect the am2320 to the Raspbery Pi I2C pins

Raspberry Pi 3B/4 Pins:

- Board 3.3V (pin 1) to sensor VIN (pin 1)
- Board SDA (pin 3) to sensor SDA (pin 2)
- Board GND (pin 6) to sensor GND (pin 3)
- Board SCL (pin 5) to sensor SCL (pin 4)

You may also need to add two I2C pullup resistors if your board does not already have them. The Raspberry Pi does have internal pullup resistors but it doesnt hurt to add them anyway. You can use 2.2K - 10K but we will just use 10K. The resistors go from VDD to SCL and SDA each.

Software install:
- `sudo pip3 install adafruit-circuitpython-am2320`
- edit `/etc/netdata/netdata.conf`
- find `[plugin:python.d]`
- add `command options = -ppython3`
- save the file.
- restart the netdata service.
- check the dashboard.
69 changes: 69 additions & 0 deletions collectors/python.d.plugin/am2320/am2320.chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# _*_ coding: utf-8 _*_
# Description: AM2320 netdata module
# Author: tommybuck
# SPDX-License-Identifier: GPL-3.0-or-Later

try:
import board
import busio
import adafruit_am2320
HAS_AM2320 = True
except ImportError:
HAS_AM2320 = False


from bases.FrameworkServices.SimpleService import SimpleService


ORDER = [
'temperature',
'humidity',
]

CHARTS = {
'temperature': {
'options': [None, 'Temperature', 'celsius', 'temperature', 'am2320.temperature', 'line'],
'lines': [
['temperature']
]
},
'humidity': {
'options': [None, 'Relative Humidity', 'percentage', 'humidity', 'am2320.humidity', 'line'],
'lines': [
['humidity']
]
}
}


class Service(SimpleService):
def __init__(self, configuration=None, name=None):
SimpleService.__init__(self, configuration=configuration, name=name)
self.order = ORDER
self.definitions = CHARTS
self.am = None

def check(self):
if not HAS_AM2320:
self.error("Could not find the adafruit-circuitpython-am2320 package.")
return False

try:
i2c = busio.I2C(board.SCL, board.SDA)
self.am = adafruit_am2320.AM2320(i2c)
except ValueError as error:
self.error("error on creating I2C shared bus : {0}".format(error))
return False

return True

def get_data(self):
try:
return {
'temperature': self.am.temperature,
'humidity': self.am.relative_humidity,
}

except (OSError, RuntimeError) as error:
self.error(error)
return None
68 changes: 68 additions & 0 deletions collectors/python.d.plugin/am2320/am2320.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# netdata python.d.plugin configuration for am2320 temperture/humity sensor
#
# This file is in YaML format. Generally the format is:
#
# name: value
#
# There are 2 sections:
# - global variables
# - one or more JOBS
#
# JOBS allow you to collect values from multiple sources.
# Each source will have its own set of charts.
#
# JOB parameters have to be indented (using spaces only, example below).

# ----------------------------------------------------------------------
# Global Variables
# These variables set the defaults for all JOBs, however each JOB
# may define its own, overriding the defaults.

# update_every sets the default data collection frequency.
# If unset, the python.d.plugin default is used.
# update_every: 1

# priority controls the order of charts at the netdata dashboard.
# Lower numbers move the charts towards the top of the page.
# If unset, the default for python.d.plugin is used.
# priority: 60000

# penalty indicates whether to apply penalty to update_every in case of failures.
# Penalty will increase every 5 failed updates in a row. Maximum penalty is 10 minutes.
# penalty: yes

# autodetection_retry sets the job re-check interval in seconds.
# The job is not deleted if check fails.
# Attempts to start the job are made once every autodetection_retry.
# This feature is disabled by default.
# autodetection_retry: 0

# ----------------------------------------------------------------------
# JOBS (data collection sources)
#
# The default JOBS share the same *name*. JOBS with the same name
# are mutually exclusive. Only one of them will be allowed running at
# any time. This allows autodetection to try several alternatives and
# pick the one that works.
#
# Any number of jobs is supported.
#
# All python.d.plugin JOBS (for all its modules) support a set of
# predefined parameters. These are:
#
# job_name:
# name: myname # the JOB's name as it will appear at the
# # dashboard (by default is the job_name)
# # JOBs sharing a name are mutually exclusive
# update_every: 1 # the JOB's data collection frequency
# priority: 60000 # the JOB's order on the dashboard
# penalty: yes # the JOB's penalty
# autodetection_retry: 0 # the JOB's re-check interval in seconds
#
# Additionally to the above, example also supports the following:
#
# - none
#
# ----------------------------------------------------------------------
# AUTO-DETECTION JOBS
# only one of them will run (they have the same name)
1 change: 1 addition & 0 deletions collectors/python.d.plugin/python.d.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gc_interval: 300

# apache_cache has been replaced by web_log
# adaptec_raid: yes
# am2320: yes
apache_cache: no
# beanstalk: yes
# bind_rndc: yes
Expand Down
1 change: 1 addition & 0 deletions health/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dist_userhealthconfig_DATA = \
healthconfigdir=$(libconfigdir)/health.d
dist_healthconfig_DATA = \
health.d/adaptec_raid.conf \
health.d/am2320.conf \
health.d/apache.conf \
health.d/apcupsd.conf \
health.d/backend.conf \
Expand Down
12 changes: 12 additions & 0 deletions health/health.d/am2320.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# make sure am2320 is sending stats

template: am2320_last_collected_secs
on: am2320.temperature
calc: $now - $last_collected_t
units: seconds ago
every: 10s
warn: $this > (($status >= $WARNING) ? ($update_every) : ( 5 * $update_every))
crit: $this > (($status == $CRITICAL) ? ($update_every) : (60 * $update_every))
delay: down 5m multiplier 1.5 max 1h
info: number of seconds since the last successful data collection
to: webmaster
2 changes: 1 addition & 1 deletion packaging/makeself/install-or-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fi
# -----------------------------------------------------------------------------
progress "Attempt to create user/group netdata/netadata"

NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody"
NETDATA_WANTED_GROUPS="docker nginx varnish haproxy adm nsd proxy squid ceph nobody I2C"
NETDATA_ADDED_TO_GROUPS=""
# Default user/group
NETDATA_USER="root"
Expand Down
7 changes: 7 additions & 0 deletions web/gui/dashboard_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,14 @@ netdataDashboard.menu = {
title: 'HDFS',
icon: '<i class="fas fa-folder-open"></i>',
info: 'Provides <b><a href="https://hadoop.apache.org/docs/r3.2.0/hadoop-project-dist/hadoop-hdfs/HdfsDesign.html">Hadoop Distributed File System</a></b> performance statistics. Module collects metrics over <code>Java Management Extensions</code> through the web interface of an <code>HDFS</code> daemon.'
},

'am2320': {
title: 'AM2320 Sensor',
icon: '<i class="fas fa-thermometer-half"></i>',
info: 'Readings from the external AM2320 Sensor.'
}

};


Expand Down

0 comments on commit 3fdf18d

Please sign in to comment.