Skip to content

Instantly share code, notes, and snippets.

View LuisFDuarte's full-sized avatar

Luis Felipe Duarte Herrera LuisFDuarte

View GitHub Profile
@LuisFDuarte
LuisFDuarte / gist:42a2ebb6ae36125b68cc
Last active August 29, 2015 14:03
This code runs on a Raspberry Pi device, with a motion sensor connected to it.
import RPi.GPIO as GPIO ##GPIO library
from ubidots import ApiClient ##Ubidots Library
import time ##time library for delays
GPIO.setmode(GPIO.BCM)##set up BCM as numbering system for inputs
GPIO.setup(7,GPIO.IN)##Declaring GPIO7 as input for the sensor
try:
api=ApiClient("75617caf2933588b7fd0da531155d16035138535")##put your own apikey
people= api.get_variable("53b9f8ff76254274effbbace")##put your own variable's id
except:
#!/usr/bin/env python
import time # Library for delays
import RPi.GPIO as GPIO # Library for using the GPIO ports
from math import log1p,exp,log10 # Library for math functions. No need for it if you'll get the raw data from the sensors
from ubidots import ApiClient # Ubidots Library
import Adafruit_DHT # Library from Adafruit to simplify the use of DHT sensor.
# Set up the SPI interface pins. Through SPI we can connect to the ADC MCP3008
SPICLK = 18
#!/usr/bin/env python
import time # Library for delays
import RPi.GPIO as GPIO # Library for using the GPIO ports
from math import log1p,exp,log10 # Library for math functions. No need for it if you'll get the raw data from the sensors
from ubidots import ApiClient # Ubidots Library
import Adafruit_DHT # Library from Adafruit to simplify the use of DHT sensor.
import random
# Set up the SPI interface pins. Through SPI we can connect to the ADC MCP3008
SPICLK = 18
import pifacedigitalio #Library for pifacedigitalio #Library for delays
from ubidots import ApiClient #Library for Ubidots
pifacedigital = pifacedigitalio.PiFaceDigital() #Declare piface object
##Connect to Ubidots
try:
api = ApiClient("1fc7a56bf4b539725ace7a3f4aa623e9e9620612") #Don't forget to put your own Apikey
valve = api.get_variable('53cd4cb07625425b70f5c21e') #Put here your valve ID's
valveState = api.get_variable("53ce95547625420403d81468") #Put here your realy state ID's
const SPICLK = 937.5;
// Class to read the DHT11 temperature/humidity sensor
// These sensors us a proprietary one-wire protocol. The imp
// emulates this protocol with SPI.
// To use:
// - tie MOSI to MISO with a 10k resistor
// - tie MISO to the data line on the sensor
class DHT11 {
static STARTTIME_LOW = 0.001000; // 1 ms low time for start
static STARTTIME_HIGH = 0.000020; // 20 us min high time for start
device.on("temp", function(value) {
server.log("Trying to post to Ubi the value:");
server.log(value);
local headers = { "Content-Type": "application/json", "X-Auth-Token": "NBbF3PWPxWc2IaO40aXOKnhIu8tOv92rYN3ibiEc7Jh6GV3KZUUCHtXuNz7Y" }; // Replace the token with yours
local url = "http://things.ubidots.com/api/v1.6/variables/53d2beb37625424630223dac/values"; // Replace the Variable ID with yours
local string = {"value": value};
local request = http.post(url, headers, http.jsonencode(string));
local response = request.sendsync();
});
#include <WiFiShieldOrPmodWiFi_G.h> // This is for the MRF24WGxx on a pmodWiFi or WiFiShield
#include <DNETcK.h>
#include <DWIFIcK.h>
//Wifi Variables
char * server = "things.ubidots.com"; // server to connect to
unsigned short portServer = 80;
const char * szSsid = "Atom House Medellin";// Specify the SSID
#define USE_WPA2_PASSPHRASE
#if defined(USE_WPA2_PASSPHRASE)
device.on("temp", function(value) {
//server.log("Trying to post to Ubi the value:");
//server.log(value);
local headers = { "Content-Type": "application/json", "X-Auth-Token": "NBbF3PWPxWc2IaO40aXOKnhIu8tOv92rYN3ibiEc7Jh6GV3KZUUCHtXuNz7Y" }; // Replace the token with yours
local url = "http://things.ubidots.com/api/v1.6/variables/53d2beb37625424630223dac/values"; // Replace the Variable ID with yours
local string = {"value": value};
local request = http.post(url, headers, http.jsonencode(string));
local response = request.sendsync();
});
device.on("hum", function(value) {
const SPICLK = 937.5;
// Class to read the DHT11 temperature/humidity sensor
// These sensors us a proprietary one-wire protocol. The imp
// emulates this protocol with SPI.
// To use:
// - tie MOSI to MISO with a 10k resistor
// - tie MISO to the data line on the sensor
class DHT11 {
static STARTTIME_LOW = 0.001000; // 1 ms low time for start
static STARTTIME_HIGH = 0.000020; // 20 us min high time for start
// This #include statement was automatically added by the Spark IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
// This #include statement was automatically added by the Spark IDE.
#include "HttpClient/HttpClient.h"
HttpClient http;
#define VARIABLE_ID "53f6caea76254277ef8837cd"
#define VARIABLE_ID2 "53f63fa576254235bec59148"
#define TOKEN "cfaI5R1bcr7wlwf58hAnNZNNvfSoUk"
int lightLevel = 0;