File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (C) Orange
3+ #
4+ # This software is distributed under the terms and conditions of the 'MIT'
5+ # license which can be found in the file 'LICENSE.md' in this package distribution
6+ import sys
7+ import time
8+ import LiveObjects
9+
10+ import busio
11+ import adafruit_vl6180x
12+
13+ try :
14+ import board
15+ except NotImplementedError : # if no I2C device
16+ sys .exit ()
17+
18+ # Create I2C bus
19+ i2c = busio .I2C (board .SCL , board .SDA )
20+ # Create sensor instance.
21+ sensor = adafruit_vl6180x .VL6180X (i2c )
22+ # You can add an offset to distance measurements here (e.g. calibration)
23+ # Swapping for the following would add a +10 millimeter offset to measurements:
24+ # sensor = adafruit_vl6180x.VL6180X(i2c, offset=10)
25+
26+ # Create LiveObjects
27+ lo = LiveObjects .Connection ()
28+
29+ MESSAGE_RATE = 5
30+
31+ # Main program
32+ lo .connect () # Connect to LiveObjects
33+ last = uptime = time .time ()
34+
35+ while True :
36+ if (time .time ()) >= last + MESSAGE_RATE :
37+ # lo.add_to_payload("uptime", int(time.time() - uptime)) # Add value to payload: name - value
38+ lo .add_to_payload ("distance" , sensor .range )
39+ lo .add_to_payload ("ambient_light" , sensor .read_lux (adafruit_vl6180x .ALS_GAIN_1 ))
40+ lo .send_data () # Sending data to cloud
41+ last = time .time ()
42+ lo .loop () # Check for incoming messages and if connection is still active
Original file line number Diff line number Diff line change @@ -210,10 +210,24 @@ def get_client_id(self):
210210 return self .get_lang_str () + ':' + get_mac ()
211211
212212
213+ class RaspberryPi (Linux ):
214+ pass
215+
216+
217+ def is_raspberrypi ():
218+ try :
219+ with open ('/proc/device-tree/model' ) as f :
220+ return f .read ().startswith ('Raspberry' )
221+ except FileNotFoundError :
222+ return False
223+
224+
213225class BoardsFactory :
214226
215227 def __new__ (cls , net_type ):
216228 s = sys .platform
217229 sn = s [0 ].upper () + s [1 :] # capitalize first letter
230+ if sn == 'Linux' :
231+ sn = 'RaspberryPi' if is_raspberrypi () else 'Linux'
218232 board = eval (sn )(net_type ) # instance of board w/ net type: WiFi, LTE, etc.
219233 return board
You can’t perform that action at this time.
0 commit comments