Last active
December 14, 2015 08:59
-
-
Save metadaddy/5061951 to your computer and use it in GitHub Desktop.
Controlling physical devices from a Raspberry Pi and approvals in Force.com!
This file contains 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
trigger LightTrigger on Light__c (before update) { | |
for (Light__c light : Trigger.new) { | |
Light__c beforeUpdate = System.Trigger.oldMap.get(light.Id); | |
if (light.State__c == 'On' && beforeUpdate.State__c != 'On') { | |
ButtonController.light(true); | |
} else if (light.State__c == 'Off' && beforeUpdate.State__c != 'Off') { | |
ButtonController.light(false); | |
} | |
} | |
} |
This file contains 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 RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BCM) | |
# We only work with pin 25 for now, but it would be easy to extend this to as many pins as desired | |
GPIO.setup(25, GPIO.OUT) | |
GPIO.output(25, GPIO.HIGH) | |
time.sleep(1) | |
GPIO.output(25, GPIO.LOW) | |
from flask import Flask, request | |
app = Flask(__name__) | |
@app.route('/pins/<int:pin>', methods=['POST']) | |
def pins(pin): | |
state = GPIO.HIGH if request.json else GPIO.LOW | |
print("Setting pin %d to %s" % (pin, state)) | |
GPIO.output(pin, state) | |
return '', 204 | |
if __name__ == "__main__": | |
app.run('0.0.0.0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment