Skip to content

Instantly share code, notes, and snippets.

@ogavrisevs
Last active October 8, 2017 17:50
Show Gist options
  • Save ogavrisevs/acde72c2952a0ea1a802c9ae2ef5580a to your computer and use it in GitHub Desktop.
Save ogavrisevs/acde72c2952a0ea1a802c9ae2ef5580a to your computer and use it in GitHub Desktop.
Send temprature from AM2302 to AWS cloudWatch
* * * * * python /root/main.py
#!/bin/bash
sudo apt-get update
sudo apt-get install -y build-essential python-dev git vim awscli boto
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
python setup.py install
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install boto3
#!/bin/bash
gcloud container clusters get-credentials cluster-1 --zone europe-west1-d --project midyear-respect-167907
helm init
helm install --name grafana --set server.adminPassword=m********a --set server.persistentVolume.enabled=false --set server.service.type=LoadBalancer stable/grafana
//password
kubectl get secret --namespace default grafana-grafana -o jsonpath="{.data.grafana-admin-password}" | base64 --decode ; echo
//ip
kubectl get service --namespace default -l "app=grafana-grafana,component=grafana" -o jsonpath="{.items[0].status.loadBalancer.ingress[0]}"
docker run \
-d \
--restart always \
-p 3210:3000 \
--name=grafana \
grafana/grafana:latest
{
"annotations": {
"list": []
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"hideControls": false,
"id": 1,
"links": [],
"rows": [
{
"collapse": false,
"height": "250px",
"panels": [
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": null,
"fill": 1,
"id": 1,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": true,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"alias": "temp",
"dimensions": {
"Location": "Dzidrinas"
},
"metricName": "temperature",
"namespace": "Iot",
"period": "",
"refId": "A",
"region": "eu-central-1",
"statistics": [
"Average"
]
},
{
"alias": "hum",
"dimensions": {
"Location": "Dzidrinas"
},
"metricName": "humidity",
"namespace": "Iot",
"period": "",
"refId": "B",
"region": "eu-central-1",
"statistics": [
"Average"
]
}
],
"thresholds": [],
"timeFrom": null,
"timeShift": null,
"title": "Panel Title",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"format": "none",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
]
}
],
"repeat": null,
"repeatIteration": null,
"repeatRowId": null,
"showTitle": false,
"title": "Dashboard Row",
"titleSize": "h6"
}
],
"schemaVersion": 14,
"style": "dark",
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-3h",
"to": "now"
},
"timepicker": {
"refresh_intervals": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
],
"time_options": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
},
"timezone": "browser",
"title": "Main",
"version": 1
}
#!/bin/bash
helm install --name grafana --set server.adminPassword=m**********a --set server.persistentVolume.enabled=false --set server.serviceType=LoadBalancer stable/grafana
kubectl get secret --namespace default grafana-grafana -o jsonpath="{.data.grafana-ad-password}" | base64 --decode ; echo
from datetime import datetime
import boto3
import sys
import Adafruit_DHT
cloudwatch = boto3.client('cloudwatch')
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity))
cloudwatch.put_metric_data(
MetricData=[
{
'MetricName': 'temperature',
'Dimensions': [
{
'Name': 'Location',
'Value': 'Dzidrinas'
},
],
'Value': temperature
},
],
Namespace='Iot'
)
cloudwatch.put_metric_data(
MetricData=[
{
'MetricName': 'humidity',
'Dimensions': [
{
'Name': 'Location',
'Value': 'Dzidrinas'
},
],
'Value': humidity
},
],
Namespace='Iot'
)
else:
print('Failed to get reading. Try again!')
sys.exit(1)
[default]
region = eu-central-1
[default]
aws_access_key_id = AK***************MA
aws_secret_access_key = L1***************************0v
@ogavrisevs
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment