def push(feeder_id, data_dict):
    data_dict['request_id'] = str(uuid.uuid4())
    json_obj = json.dumps(data_dict)
    if False:
        print(feeder_id)
        print(json_obj)
    publish(settings.FEEDER_PUSH_CHANNEL_ID.format(id=feeder_id),
            payload=json_obj)
def push(feeder_id, data_dict):
    data_dict['request_id'] = str(uuid.uuid4())
    json_obj = json.dumps(data_dict)
    #print("WARNING: PUSH IS NOT ENABLED. ENABLE IN mqtt_utils.py")
    print(feeder_id)
    print(json_obj)
    publish(settings.FEEDER_PUSH_CHANNEL_ID.format(id=feeder_id),
            payload=json_obj)
Beispiel #3
0
    def publish_connected(self):
        ''' publish connected status: 2 = connected, 0 = disconnected '''

        topic = f'tentacle/connected/{self.sensor_id}'
        publish(topic,
                payload='2',
                will={
                    'topic': topic,
                    'payload': '0',
                    'qos': 2,
                    'retain': True
                })
Beispiel #4
0
 def kirimData(self):
     a = self.sensors[0]
     b = self.sensors[1]
     c = self.sensors[2]
     d = self.sensors[3]
     e = self.sensors[4]
     f = self.sensors[5]
     g = self.sensors[6]
     h = self.sensors[7]
     msg = HEADER_SENSOR + ",{},{},{},{},{},{},{},{}".format(
         a, b, c, d, e, f, g, h)
     publish(TOPIC_STATUS, msg)
     print("[VL53] Publishing", msg)
Beispiel #5
0
def on_message(client, userdata, message):
    if config.MQTT_SERVER != "mqtt.eclipse.org":  #deactivate for demo server
        msg = message.payload.decode("utf-8")
        print("message received ", str(msg))
        print("message topic=", message.topic)
        print("message qos=", message.qos)
        print("message retain flag=", message.retain)

        if message.topic.startswith(config.MQTT_PATH + "/set/relais"):
            channel = int(message.topic[-1])
            assert 0 < channel < 4, 'channel outside 1..3'
            if msg == 'ON':
                peripherals.controlrelays(channel, 1)
                publish("relais" + channel, 'ON')
            elif msg == 'OFF':
                peripherals.controlrelays(channel, 0)
                publish("relais" + channel, 'OFF')
            else:
                print('unknown:' + message.topic + ' message:' + msg)

        if message.topic == (config.MQTT_PATH + "/set/buzzer"):

            if msg == 'ON':
                peripherals.controlrelays(4, 1)
                publish("buzzer", 'ON')
            elif msg == 'OFF':
                peripherals.controlrelays(4, 0)
                publish("buzzer", 'OFF')
            else:
                print('unknown:' + message.topic + ' message:' + msg)

        if message.topic == (config.MQTT_PATH + "/set/d13"):

            if msg == 'ON':
                peripherals.controlrelays(5, 1)
                publish("d13", 'ON')
            elif msg == 'OFF':
                peripherals.controlrelays(5, 0)
                publish("d13", 'OFF')
            else:
                print('unknown:' + message.topic + ' message:' + msg)

        if message.topic == (config.MQTT_PATH + "/set/alert"):

            if msg == 'ON':
                peripherals.eg_object.alert = 1
                publish("alert", 'ON')
            elif msg == 'OFF':
                peripherals.eg_object.alert = 0
            else:
                print('unknown:' + message.topic + ' message:' + msg)

        if message.topic == (config.MQTT_PATH + "/set/max_backlight"):
            assert 0 < (int)(msg) < 32, 'value outside 1..31'
            peripherals.eg_object.max_backlight = (int)(msg)
            peripherals.controlbacklight((int)(msg))

        if message.topic == (config.MQTT_PATH + "/set/vent_pwm"):
            assert -1 < (int)(msg) < 256, 'value outside 0..255'
            peripherals.controlvent((int)(msg))

        if message.topic == (config.MQTT_PATH + "/set/set_temp"):
            assert 0 < (float)(msg) < 50, 'value outside 1..50'
            peripherals.eg_object.set_temp = (float)(msg)

        if message.topic == (config.MQTT_PATH + "/set/led"):
            value = msg.split(',')
            if len(value) == 3:
                peripherals.controlled(value)
Beispiel #6
0
import paho.mqtt.publish as publish
from tentacle_pi.TSL2561 import TSL2561
topic = "raspBerry/test"
publish(topic, payload=None, qos=0, retain=False)
Beispiel #7
0
    def publish_measurement(self, capability, payload):
        ''' publish a mesaurement with payload value=24.5;unit=°C '''

        publish(f'tentacle/status/{self.sensor_id}/measurement/{capability}',
                payload=payload)
Beispiel #8
0
    def publish_capabilities(self):
        ''' publish the capabilities, i.e. temperature;pressure;humidity '''

        publish(f"tentacle/status/{self.sensor_id}/capabilities",
                payload=dumps(self.capabilities))
Beispiel #9
0
    def publish_interval(self):
        ''' publish the measurement interval in seconds '''

        publish(f'tentacle/status/{self.sensor_id}/interval',
                payload=str(self.interval))
Beispiel #10
0
def absentThread():  # to publish "no motion" after a period of time
    publish(PIR_SENSOR_TOPIC, 0)
Beispiel #11
0
def publishOutdoorTemperature(value):
    publish(OUT_OUTDOOR_TEMPERATURE_TOPIC, value)
Beispiel #12
0
def publishDailyRain(period, value):
    topic = DAILY_RAIN_TOPIC.replace("~period~", str(period))
    publish(topic, value)
Beispiel #13
0
def publishHourlyRain(period, value):
    topic = HOURLY_RAIN_TOPIC.replace("~period~", str(period))
    publish(topic, value)
Beispiel #14
0
def publishLightning(period, value):
    topic = OUT_LIGHTNING_TOPIC.replace("~period~", str(period))
    publish(topic, value)
Beispiel #15
0
logging.basicConfig(
    level=logging.INFO,
    datefmt='%Y-%m-%d %H:%M:%S',
    format='%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s',
)

parser = argparse.ArgumentParser(
    description='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g',
                    dest='gpio',
                    type=int,
                    default=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))
while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        publish("test/message", str(rfdevice.rx_code))
        logging.info(
            str(rfdevice.rx_code) + " [pulselength " +
            str(rfdevice.rx_pulselength) + ", protocol " +
            str(rfdevice.rx_proto) + "]")
    time.sleep(0.01)
rfdevice.cleanup()
 def water_writer(self):
     mqtt.publish("water")