sudo apt-get install sense-hat cat <<EOF> ~/example.py from sense_hat import SenseHat from pprint import pprint sense = SenseHat() pprint(vars(sense)) print("Humidity: %s %%rH" % sense.humidity) print("Temperature: %s C" % sense.temperature) print("Temperature: %s C" % sense.get_temperature_from_humidity()) print("Temperature: %s C" % sense.get_temperature_from_pressure()) print("Pressure: %s Millibars" % sense.get_pressure()) sense.set_imu_config(False, True, False) # gyroscope only print(sense.orientation_radians) print(sense.get_orientation_degrees()) print("North: %s" % sense.get_compass()) EOF
Humidity: 39.5838356018 %rH Temperature: 31.6538200378 C Temperature: 31.6538200378 C Temperature: 30.1583328247 C Pressure: 1017.19091797 Millibars {'yaw': 0.0, 'roll': 0.0, 'pitch': 0.0} {'yaw': 359.99058432743004, 'roll': 359.9998950151144, 'pitch': 359.9932170522769} North: 359.751439678
pip3 install webthing wget https://raw.githubusercontent.com/mozilla-iot/webthing-python/master/example/single-thing.py python3 single-thing.py
cat simplest-thing.py from __future__ import division from webthing import (Action, Event, Property, SingleThing, Thing, Value, WebThingServer) import logging import time import uuid def make_thing(): thing = Thing( 'urn:dev:ops:my-actuator-1234', 'ActuatorExample', ['OnOffSwitch'], 'An actuator example that just log' ) thing.add_property( Property(thing, 'on', Value(True, lambda v: print('On-State is now', v)), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'An actuator example that just log', })) return thing def run_server(): thing = make_thing() # If adding more than one thing, use MultipleThings() with a name. # In the single thing case, the thing's name will be broadcast. server = WebThingServer(SingleThing(thing), port=8888) try: logging.info('starting the server') server.start() except KeyboardInterrupt: logging.info('stopping the server') server.stop() logging.info('done') if __name__ == '__main__': logging.basicConfig( level=10, format="%(asctime)s %(filename)s:%(lineno)s %(levelname)s %(message)s" ) run_server() curl http://localhost:8888/properties {"on": true} curl -X PUT -d '{"on": false}' http://localhost:8888/properties/on python3 ./simplest-thing.py 2020-04-23 21:16:30,954 simplest-thing.py:37 INFO starting the server 2020-04-23 21:16:31,784 selector_events.py:53 DEBUG Using selector: EpollSelector 2020-04-23 21:16:33,379 web.py:2250 INFO 200 GET / (192.168.1.28) 7.72ms 2020-04-23 21:16:33,404 web.py:2250 INFO 200 GET /properties/on (192.168.1.28) 4.68ms 2020-04-23 21:16:35,229 web.py:2250 INFO 200 GET /properties (::1) 3.99ms 2020-04-23 21:16:52,116 web.py:2250 WARNING 405 PUT /properties (::1) 5.13ms 2020-04-23 21:16:54,006 web.py:2250 WARNING 405 PUT /properties (::1) 4.05ms On-State is now False 2020-04-23 21:16:56,366 web.py:2250 INFO 200 PUT /properties/on (::1) 11.06ms
<code> https://github.com/mozilla-iot/gateway/releases//download/0.12.0/gateway-0.12.0.img.zip
“WebThings Gateway 63CE”
WiFi Setup
Connecting to Wi-Fi… Please ensure you are connected to the same network and then navigate to gateway.local in your web browser to continue setup.
mkdir -p ~/sense-hat-webthing cd ~/sense-hat-webthing pip3 install webthing