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
#!/usr/bin/env python3 | |
import paho.mqtt.publish as publish | |
from subprocess import check_output | |
from re import findall | |
def get_temp(): | |
temp = check_output(["vcgencmd","measure_temp"]).decode("UTF-8") | |
return(findall("\d+\.\d+",temp)[0]) | |
def publish_message(topic, message): |
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
#!/usr/bin/env python3 | |
from subprocess import check_output | |
from re import findall | |
def get_temp(): | |
temp = check_output(["vcgencmd","measure_temp"]).decode("UTF-8") | |
return(findall("\d+\.\d+",temp)[0]) | |
print(get_temp()) |
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
""" | |
A bot with servos for an Adafruit Feather Huzzah | |
Requires the Adafruit PWM servo library: | |
https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library | |
Uses a FeatherWing servo board attached with i2C | |
""" | |
import machine | |
import servo | |
import utime |
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
def stop(): | |
"""Stops the wheels""" | |
servos.position(left_wheel, degrees=90) | |
servos.position(right_wheel, degrees=90) | |
def fw_step(): | |
"""Moves the bot forward one step""" | |
servos.position(left_wheel, degrees=90 + wheel_speed) | |
servos.position(right_wheel, degrees=90 - wheel_speed + drift) | |
utime.sleep(straight_length) |
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
action_methods = { | |
'F' : wheels.fw_step, | |
'B' : wheels.back_step, | |
'L' : wheels.turn_left, | |
'R' : wheels.turn_right, | |
'S' : wheels.stop, | |
'U' : hammer.up, | |
'D' : hammer.down, | |
'O' : claws.open, | |
'C' : claws.close |
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
from umqtt.simple import MQTTClient | |
import utime | |
from machine import Pin | |
import oled_message_display | |
import wifi_connection | |
last_messages = {} | |
def mqtt_message_received(topic, msg): | |
# add or update the latest stored message for this topic |
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 machine | |
i2c = machine.I2C(machine.Pin(5), machine.Pin(4)) | |
import ssd1306 | |
oled = ssd1306.SSD1306_I2C(128, 32, i2c) | |
oled.fill(0) | |
oled.text("First line", 0, 0) | |
oled.text("Second line", 0, 10) | |
oled.text("Third line", 0, 20) | |
oled.show() |
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
from umqtt.simple import MQTTClient | |
import utime | |
c = MQTTClient("umqtt_client", "192.168.1.16",port=1883) | |
c.set_callback(mqtt_message_received) | |
c.connect() | |
c.subscribe("Home/#") | |
while True: | |
c.check_msg() |
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 network | |
import utime | |
def setup_wifi(): | |
sta_if = network.WLAN(network.STA_IF) | |
sta_if.active(True) | |
# Replace with your SSID and WiFi password | |
sta_if.connect('SSID', 'PASSWORD') | |
while not sta_if.isconnected(): | |
utime.sleep(1) |
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
# Turn on outdoor lights in the afternoon | |
00 17 * * * curl -i -H "Content-Type: application/json" -X PUT -d '{"state":"on"}' http://localhost:5000/Outlets/api/outlets/2/1 | |
# Turn off outdoor lights in the morning | |
00 08 * * * curl -i -H "Content-Type: application/json" -X PUT -d '{"state":"off"}' http://localhost:5000/Outlets/api/outlets/2/1 | |
# Turn on downstairs window lights in the afternoon | |
30 19 * * * curl -i -H "Content-Type: application/json" -X PUT -d '{"state":"on"}' http://localhost:5000/Outlets/api/outlets/1/2 | |
# Turn on upstairs window lights in the evening |