Ejemplo n.º 1
0
class Controller:
    def __init__(self):

        self.monitor_thread=None
        self.button = None
        self.a11 = None
        self.board = ArduinoDue('/dev/ttyS0')


    def mqtt_monitor(self):
        """ monitor sensor data
         """
        global cLient
        if self.monitor_thread==None:
            cLient.connect("gpssensor.ddns.net", 1883, 60)
            self.monitor_thread = MonitorThread()
            self.monitor_thread.start()
        else:
            print("MQTT client already exist! Don't start again")
    
    def mqtt_send(self,payload):
        #client = new mqtt.MqttClient("tcp://gpssensor.ddns.net:1883", "LASS-Wuuong");
        #client.connect();
        #MqttMessage message = new MqttMessage();
        #message.setPayload("A single message".getBytes());
        #client.publish("LASS/Test/LinkItSmart7688-Test", message);
        #client.disconnect();
        publish.single("LASS/Test/LinkItSmart7688-Test", payload, hostname="gpssensor.ddns.net")
    
    def board_led_blink(self):
        self.board.digital[13].write(1)
        sleep(0.5)
        self.board.digital[13].write(0)
        sleep(0.5)
    
    def board_d_reporting(self):
        iterator = util.Iterator(self.board)
        iterator.start()
        sleep(1)
        self.button = self.board.get_pin('d:4:i')
        sleep(1)
        self.button.enable_reporting()
        sleep(1)
        
    def board_a_reporting(self):
        it = util.Iterator(self.board)
        it.start()
        sleep(1)
        self.button = self.board.get_pin('a:0:i')
        self.a11 = self.board.get_pin('a:11:i')
        sleep(1)
        self.button.enable_reporting()
        self.a11.enable_reporting()
        sleep(1)    
Ejemplo n.º 2
0
from pyfirmata import ArduinoDue
from pyfirmata import util

board = ArduinoDue('COM3')
LEDS = [
    board.get_pin('d:3:o'),
    board.get_pin('d:5:o'),
    board.get_pin('d:6:o'),
    board.get_pin('d:9:o')
]
SW = board.get_pin('d:10:i')

it = util.Iterator(board)
it.start()


def encode(num):
    if num < 0:
        num = 0
    elif num >= 16:
        num = 15

    str = '{0:04b}'.format(num)

    for i, value in enumerate(str):
        LEDS[i].write(int(value))

    return str


def read_sw():