Example #1
0
# (c) Sensemakersams.org and others. See https://github.com/sensemakersamsterdam/astroplant_explorer
# Author: Gijs Mos
#
# Warning: if import of ae_* modules fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from time import sleep, time
from ae_util.mqtt import AE_Local_MQTT
from ae_util.configuration import cfg
from os import system

# global variables
my_cfg = cfg['lcd_display']  # Find our bit in the config file

loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

print('** test_axa_display: sending stop request to other axa programs...')
# Stop other stuff during test.
loc_mqtt.publish(cfg['local_MQTT']['control_sub_tpc'], 'stop')
print('** test_axa_display: starting fresh axa_display...')
system('python axa_display.py&')
sleep(5)

test_cases = [
    (-1, '1- one time message, 10 secs, no priority.',
     ('{"action":"upsert", "id":"p1", "l1":"line - 1", "l2":"test 1", "secs":5}',
      )),
    (-1, '2- recurring message, 1 secs.',
     ('{"action":"upsert", "id":"p2", "l1":"line - 1", "l2":"test 2", "secs":1, "recur":true}',
Example #2
0
# (c) Sensemakersams.org and others. See https://github.com/sensemakersamsterdam/astroplant_explorer
# Author: Gijs Mos
#
# Warning: if import of ae_* modules fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from ae_util.configuration import cfg
from ae_util.mqtt import AE_Local_MQTT
from ae_drivers import AE_Pin
from ae_drivers.led import AE_LED
from time import sleep
import sys
#
# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

led = AE_LED('led', 'The red LED', AE_Pin.D20)
led.setup()

stop = False


def cb1(sub_topic, payload, rec_time):
    print('call_back 1:', sub_topic, payload, rec_time)
    if sub_topic == 'button1' and payload == 'True':
        print ('led on')
        led.value(1) 
    elif sub_topic == 'button1' and payload == 'False':
        print ('led off')
Example #3
0
    # Create sensor object and get it going
    dht = AE_DHT(sensor_name, desc, pin, sensor=sensor)
    dht.setup()
    return dht


def control_cb(sub_topic, payload, rec_time):
    """Handle application control messages.
    """
    global stop_loop
    if payload == 'stop':
        stop_loop = True


# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

# Open input channel for application control messages
loc_mqtt.subscribe('control', control_cb)

# Set-up sensor.
dht = setup_dht()

sigma_hum = 0
sigma_temp = 0
samples = 0
next_measurement = time() + measurement_interval
next_publish = time() + publish_interval

while not stop_loop:
Example #4
0
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from ae_util.configuration import cfg
from ae_util.mqtt import AE_Local_MQTT
from ae_drivers import AE_Pin
from ae_drivers.button import AE_Toggle_Button
from time import sleep

# Setup button 1
tgl1 = AE_Toggle_Button('tgl1', 'Just toggle button 1', AE_Pin.D5)
tgl1.setup()
last_tgl_state = 0
#
# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

print('\nType Cntl-C to exit and press button 1...')
print('button over MQTT demo.')
print('values published under topic: button1' )

try:
    while True:
        if tgl1.state() != last_tgl_state:
            print('sub-topic: button', loc_mqtt.publish('button1', tgl1.state()))
            last_tgl_state = tgl1.state()
            sleep(0.1) #delay a bit
except KeyboardInterrupt:
    print('\nBye bye...')
Example #5
0
"""
Sample implementation backend interface.
See https://github.com/sensemakersamsterdam/astroplant_explorer
"""
#
# (c) Sensemakersams.org and others. See https://github.com/sensemakersamsterdam/astroplant_explorer
# Author: Gijs Mos
#
# Warning: if import of ae_* modules fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from ae_util.configuration import cfg
from time import sleep
from ae_util.mqtt import AE_Local_MQTT
import sys

#
# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

# TODO priority based queuing
# TODO display background intensity
print('LCD display (axa_display.py) version 0.1 (no priority, no background intensity)')

# Get our LCD display going empty
lcd = lcd_setup()

# Set-up our panes structure and preload panes.
panes = Panes()
if 'preloads' in my_cfg:
    panes.preload(my_cfg['preloads'])

# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

# Open input channel for application control messages
loc_mqtt.subscribe(cfg['local_MQTT']['control_sub_tpc'], control_cb)

# Open input channel for display messages
loc_mqtt.subscribe(my_cfg['display_sub_tpc'], display_cb)

loc_mqtt.subscribe('debug', debug_cb)

while not stop_loop:
    # Check status and change display if needed.
    panes.lcd_tick()
    sleep(tick)
#
# (c) Sensemakersams.org and others. See https://github.com/sensemakersamsterdam/astroplant_explorer
# Author: Gijs Mos
#
# Warning: if import of ae_* modules fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from ae_util.configuration import cfg
from time import sleep
from ae_util.mqtt import AE_Local_MQTT
import sys

#
# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

stop = False


def cb1(sub_topic, payload, rec_time):
    print('call_back 1:', sub_topic, payload, rec_time)


def cb2(sub_topic, payload, rec_time):
    print('call_back 2:', sub_topic, payload, rec_time)


def cb_stop(sub_topic, payload, rec_time):
    global stop
#       mosquitto_sub -v -t "#"
# Then open a terminal window #3 and run:
#       python 1_mqtt_sender_demo.py
# This should get things starting. You can run rhe 1_mqtt_sender_demo.py
# repeatedly. The 1_mqtt_receiver_demo and mosquitto_sub will show the
# messages each time you run it.
# And if you want to send the stop-request to the 1_mqtt_receiver_demo.py, run
#       python 1_mqtt_stop_demo.py
# in terminal window #3.
# The mosquitto_sub in terminal #2 you can abort with control-c.

###
# Warning: if import of ae_* module(s) fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae 'lib' directory
# should be included in the printed path

# From the mqtt library we import the AE_Local_MQTT class which contains a bunch
# of functions we will use in this script.
from ae_util.mqtt import AE_Local_MQTT

# Here we initialize our local MQTT agent.
# It imports your MQTT settings automatically from the configuration.json file.
loc_mqtt = AE_Local_MQTT()

# And now we activate the MQTT connection.
loc_mqtt.setup()

# And now we just send (publish) the empty stop message. Just sending the
# control/stop topic is sufficiently here.
loc_mqtt.publish('control/stop')
# First we import the variable 'cfg' from the configuration library.
# it reads the JSON file configuration.json from your current directory
# and makes it available to this script as a the dictionary 'cfg'.
from ae_util.configuration import cfg

# From the standard time library we now import the function sleep()
from time import sleep

# From the mqtt library we import the AE_Local_MQTT class which contains a bunch
# of functions we will use in this script
from ae_util.mqtt import AE_Local_MQTT

# Here we initialize our local MQTT agent.
# It imports your MQTT settings automatically from the configuration.json file.
loc_mqtt = AE_Local_MQTT()

# And now we activate the MQTT connection.
loc_mqtt.setup()

# For the rest it is simple. We send some stuff and print the return code.
# We sleep a bit, send again etc.
# and then we are done.

# Send in sequence a dictionary, a string and an integer.
# A dict will be jsautomatically be JSON formatted before sending.
# All other stuff is formatted to a str first.
print('sub-topic: dict', loc_mqtt.publish('dict', cfg))
sleep(0.4)
print('sub-topic: str',
      loc_mqtt.publish('string', 'waar eens de boterbloemen bloeiden'))
# Warning: if import of ae_* modules fails, then you need to set up PYTHONPATH.
# To test start python, import sys and type sys.path. The ae module directory
# should be included.

from time import sleep
from ae_drivers import AE_Pin
from ae_drivers.dht import AE_DHT, DHT22
from ae_util.configuration import cfg
from ae_util.mqtt import AE_Local_MQTT

# Setup DHT sensor
dht1 = AE_DHT('dht1', 'Air temperature and humidity', AE_Pin.DHT, sensor=DHT22)
dht1.setup()

# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

print('\nType Cntl-C to exit and press button 1...')
print('DHT over MQTT demo.')
print('values published under topic: dht22')

try:
    while True:
        hum, temp = dht1.values()
        if hum is None or temp is None:
            print('DHT read error!')
        else:
            print(
                'dht22',
                loc_mqtt.publish(
Example #11
0
panes.add_or_replace(pane('start',
                          'AstroPlant Xplrr',
                          'Starting up...',
                          display_time=5, recurring=False))
panes.add_or_replace(pane('DT&IP',
                          '*date_time*',
                          '*IP*',
                          display_time=1.5, recurring=True))


# Setup the LCD
lcd = lcd_setup()


# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

# Open input channel for application control messages
loc_mqtt.subscribe('control', control_cb)

# Open input channel for display messages
loc_mqtt.subscribe(dht_sub_topic, display_cb)


while not stop_loop:

    sleep(0.2)

fan.off()
print('Got stop request. Display exits')
Example #12
0
def dht_cb(sub_topic, payload, rec_time):
    """Handle DHT messages.
    """
    global temperature, humidity
    try:
        result = json.loads(payload)
        if result[dht_sensor_name]['samples'] > 0:
            temperature = result[dht_sensor_name]['temperature']
            humidity = result[dht_sensor_name]['humidity']
    except Exception as ex:
        print('Fan', ex)


# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()

# Setup fan in off state
fan = setup_fan()

# Open input channel for application control messages
loc_mqtt.subscribe('control', control_cb)

# open input channel for sensor messages
loc_mqtt.subscribe(dht_sub_topic, dht_cb)

while not stop_loop:
    # print(temperature)
    if temperature is not None:
        if temperature >= threshold_temp and fan.is_off():
    if t < 1440:
        return (list[-1][1])


red_list = makeList("red")
blue_list = makeList("blue")
farred_list = makeList("farred")
#print((red_list), (blue_list), farred_list) # for debugging

red_value = 0
blue_value = 0
farred_value = 0

#
# Setup our local MQTT agent. Parameters are obtained from the ./configuration.json file.
loc_mqtt = AE_Local_MQTT()
loc_mqtt.setup()
#
print('\nType Cntl-C to exit and press button 1...')
print('Scheduled LED values over MQTT demo.')
print(
    'values published under topic: led_values and subtopic: red_value, blue_value, farred_value'
)

try:
    while True:
        # actual time expressed as minute of the day
        tm = (time.localtime()[3] * 60 + time.localtime()[4])
        print(tm)
        if red_value != led_val(red_list, tm):
            red_value = led_val(red_list, tm)