This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import paho.mqtt.client as mqtt | |
| import datetime | |
| import time | |
| from Adafruit_IO import MQTTClient | |
| # Set to your Adafruit IO key and username | |
| ADAFRUIT_IO_KEY = 'XXX' | |
| ADAFRUIT_IO_USERNAME = 'XXX' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from flask import Flask, render_template, jsonify, request | |
| from datetime import datetime, timedelta | |
| import sys | |
| import data_fake | |
| import data_mongodb | |
| app = Flask(__name__) | |
| def get_labels_and_values_for_topic(topic_name, numdays): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, timedelta | |
| from repository_base import Repository | |
| class FakeRepository(Repository): | |
| def get_data(self,topic_name, numdays): | |
| today=datetime.today() | |
| # Create some test data | |
| # Three values from yesterday and three values from today |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pymongo | |
| from datetime import datetime, timedelta | |
| from repository_base import Repository | |
| class MongoDBRepository(Repository): | |
| def get_data(self,topic_name, numdays): | |
| mongoClient=pymongo.MongoClient() | |
| db=mongoClient.SensorData | |
| yesterday=datetime.today() - timedelta(numdays) | |
| cursor = db.home_data.find({"topic":topic_name,"time":{"$gte":yesterday}}).sort("time",pymongo.ASCENDING) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime, timedelta | |
| class Repository: | |
| """Abstract base class for the repositories. | |
| The sub classes should implement the get_data method.""" | |
| def date_formatted(date): | |
| return date.strftime('%d %b %H:%M') | |
| def get_data(self,topic_name, numdays): | |
| raise NotImplementedError( "Should have implemented this" ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html ng-app="app" lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <title>Sensor data</title> | |
| <script src="/static/node_modules/angular/angular.js"></script> | |
| <script src="/static/node_modules/chart.js/dist/Chart.min.js"></script> | |
| <script src="/static/node_modules/angular-chart.js/dist/angular-chart.min.js"></script> | |
| <script src="/static/app.js"></script> | |
| </head> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myApp = angular.module('app', ["chart.js"]) | |
| .config(function($interpolateProvider) { | |
| $interpolateProvider.startSymbol('[[').endSymbol(']]'); | |
| }); | |
| myApp.controller("ChartCtrl", function ($scope,$http) { | |
| $scope.numdaysChanged = function() { | |
| requestNewData(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // A sketch for a DigiSpark USB device that detects when a door is opened | |
| // The door should have a reed switch with NC (normally closed) connected to the Vin wire of the device | |
| // When the door is opened, the reed switch is closed and the device is started | |
| // A 32-nit message is then sent via a 433 MHz signal that can be picked up by an appropriate receiver | |
| // (a Raspberry Pi in my case). | |
| // When the door is closed, the reed switch is opened and the device is shut down | |
| // | |
| // Depends on the RCSwitch library https://github.com/sui77/rc-switch | |
| // and the eeprom-library | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Uses pi_switch from https://github.com/lexruee/pi-switch-python | |
| # See pi_switch readme for details on setup | |
| from pi_switch import RCSwitchReceiver | |
| import time | |
| import paho.mqtt.client as mqtt | |
| receiver = RCSwitchReceiver() | |
| receiver.enableReceive(2) |