def do_steps(): global steps_queue if steps_queue.qsize() == 0: return steps = steps_queue.get() if (steps > 0): step_fun = forward_one_step n = steps else: step_fun = backward_one_step n = -steps freq = led.get_frequency(config.LED_PORCH) dc = led.get_duty_cycle(config.LED_PORCH) status = led.get_status(config.LED_PORCH) led.turn_on(config.LED_PORCH, 2, 50) gpio_lock.acquire() for i in range(0, n): step_fun(0.01) set_motor_input(0, 0, 0, 0) gpio_lock.release() if status == 'on': led.turn_on(config.LED_PORCH, freq, dc) else: led.turn_off(config.LED_PORCH) status_notify()
def trigger(self): bus = smbus.SMBus(1) shot = 0 status = True while True: #Parameters for write_byte_data #1. Address of the device #2. Communication data - active mode control register #3. Our data - 0 (standby mode) or 1 (active) bus.write_byte_data(0x1D, 0x2A, 1) #Read from the status register, real-time status register 0x00 #Data returned will be an array #Contents of 7 bytes read and stored in data array represent: #status (ignore), MSBx, LSBx, MSBy, LSBy, MSBz, LSBz data = bus.read_i2c_block_data(0x1D, 0x00, 7) number_of_bits = 16 MSB_z = data[5] LSB_z = data[6] zAccl = (MSB_z * 256 + LSB_z) / number_of_bits if zAccl > 2047: zAccl -= 4096 # if z acceleration changes by some great amount prev_z = 1000 if abs((prev_z - zAccl) / zAccl) >= 1.0: ### Change this bus.write_byte_data(0x1D, 0x2A, 0) # record GPS for 1 second. with open("/home/pi/SeisNode/data/shots.csv" % shot, "a+") as writefile: print("Trigger") led.turn_on() writer = csv.writer(writefile) if shot == 0: writer.writerow([ "Shot", "Time", "Lat", "Lat Err", "Lon", "Lon Err", "Alt", "Alt Err" ]) start = time.time() while time.time() - start < 1: data = self.collect_gps() data = np.concatenate([[shot], data]) writer.writerow(data) time.sleep(0.2) writefile.flush() writefile.close() shot += 1 time.sleep(30) led.turn_off() prev_z = 1000 status = True continue status = False prev_z = zAccl def collect_data(self): pass
def do_steps(): global steps_queue if steps_queue.qsize() == 0: return; steps = steps_queue.get() if (steps > 0): step_fun = forward_one_step n = steps else: step_fun = backward_one_step n = -steps freq = led.get_frequency(config.LED_PORCH) dc = led.get_duty_cycle(config.LED_PORCH) status = led.get_status(config.LED_PORCH) led.turn_on(config.LED_PORCH, 2, 50) gpio_lock.acquire() for i in range(0, n): step_fun(0.01) set_motor_input(0, 0, 0, 0) gpio_lock.release() if status == 'on': led.turn_on(config.LED_PORCH, freq, dc) else: led.turn_off(config.LED_PORCH) status_notify()
def prepare(): # gpio GPIO.setmode(GPIO.BCM) with connection.cursor() as cursor: sql = "select * from rooms" cursor.execute(sql) rooms = cursor.fetchall() for room in rooms: GPIO.setup(room["locked_led_port"], GPIO.OUT) GPIO.setup(room["unlocked_led_port"], GPIO.OUT) GPIO.setup(room["switch_port"], GPIO.IN) led.turn_off(room) # sound subprocess.call("sudo amixer cset numid=3 1", shell=True)
def unlock(nfc): umbrella = get_registered_umbrella(nfc) room = get_registered_room(umbrella) led.locked(room) if switch.take(room): with connection.cursor() as cursor: sql = "update umbrellas set in_room=%s where id=%s" cursor.execute(sql, (False, umbrella["id"])) connection.commit() led.turn_off(room) print "umbrella is successfully fetched" else: led.locked(room) print "umbrella is not fetched"
def light_off(name): print('light_off: %s' % name) if name == 'living': led.turn_off(config.LED_LIVING) elif name == 'bedroom': led.turn_off(config.LED_BEDROOM) elif name == 'porch': led.turn_off(config.LED_PORCH)
beamheaders = {'Content-Type': "application/json"} response = requests.request("POST", beamurl, data=json.dumps(beampayload), headers=beamheaders) # Beam will pass back the response from the Anomaly Detector API, and we'll save it as JSON. azureresponse = json.loads(response.text) # This will print out isAnomaly: True or False depending on the boolean value returned. print("isAnomaly: ", azureresponse["isAnomaly"]) # If the value is True, and anomaly is detected and the LED will turn on. if azureresponse["isAnomaly"] == True: print("Anomaly detected. Turning on LED.") led.turn_on() # Otherwise, its False, and we'll keep it off. This will turn it off it was true previously as well. else: print("No anomaly detected. LED off.") led.turn_off() except Exception as e: print(e) print("***") # sleep until next loop time_to_wait = loop_start_time + interval - time.time() if time_to_wait > 0: time.sleep(time_to_wait)