print("*******************") print("Starting simulation....") # # reading file name from command line args # fName = sys.argv[1] newRaceId = sys.argv[2] print("") print("File name: ", fName) # MQTT connectivity is encapsulated in Device class gateway = Device() gateway.connect() nMsgs = 1 # open the input file and then... read, publish loop try: with open(fName) as csvfile: readerCSV = csv.reader(csvfile, delimiter=';') # wait for MQTT connection OK # (at this point should be connected) gateway.wait_for_conn_ok() # read line by line... for row in readerCSV: tempo = row[0]
from Device import Device import Animations import math import time import threading from Utils import * led_c = 4 * 2 * 4 dev = Device(led_count=led_c, servo_count=3, brightness=0.8, update_rate=50) dev.connect() dev.start() ################################################################ anim_rate = 70 l1 = Animations.Linear2_i_1(speed=25 / anim_rate) l2 = Animations.Linear_i_1(speed=50 / anim_rate) sin1 = Animations.Sin_n_i_1(speed=120 / anim_rate) rgb_v1 = Animations.RGB_sin_v1_full_led(dev, speed=120 / anim_rate) anim_now = "none" sin_arr = Animations.Sin_arr_i_1(led_c, speed=1 / anim_rate, k=5) def anim(): while True: if anim_now == "rgb_v1": rgb_v_leds = rgb_v1.tick()
config.read(OBD2HOME + '/gateway.ini') carID = config['DEFAULT']['carID'] # should be read from config file HOST = "ubuntucontainers-dashboariotnew-zekci6cs.srv.ravcloud.com" PORT = 8883 # clientID is passed to make possible different clientID # MQTT doesn't allow different clients with same ID (second is disconnected) gateway = Device("googshut1") # try connecting in loop # to handle case in which initially no network connection while gateway.isConnected() != True: try: gateway.connect(HOST, PORT, "YES") except: print('*** Error in MQTT connection !') print('\n') print('*** Error info: ', sys.exc_info()[0], sys.exc_info()[1]) time.sleep(sleepTime) button = aiy.voicehat.get_button() button.on_press(on_button_press) while True: print('Another loop...') time.sleep(5)
config.read(OBD2HOME + '/gateway.ini') carID = config['DEFAULT']['carID'] # clientID is passed to make possible different clientID # MQTT doesn't allow different clients with same ID (second is disconnected) gateway = Device("gx2gps") # init serial # Here I have used the custom defined name: kpn_gps ser = serial.Serial('/dev/kpn_gps', 4800, timeout=10) # try connecting to local MQTT broker in loop # to handle case in which initially no network connection while gateway.isConnected() != True: try: gateway.connect("localhost", 1883, "NO") except: print('*** Error in MQTT connection !') print('*** Error info: ', sys.exc_info()[0], sys.exc_info()[1]) time.sleep(sleepTime) # # main loop # while True: gps = ser.readline() # print(gps) try: