예제 #1
0
def make_dht22_sensors(wiring_config):
    """Creates sensors derived from the DHT22 sensor.

    Args:
        wiring_config: Wiring configuration for the GreenPiThumb.

    Returns:
        A two-tuple where the first element is a temperature sensor and the
        second element is a humidity sensor.
    """
    local_dht22 = dht22.CachingDHT22(
        lambda: Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, wiring_config.
                                        gpio_pins.dht22), clock.Clock())
    return temperature_sensor.TemperatureSensor(
        local_dht22), humidity_sensor.HumiditySensor(local_dht22),
예제 #2
0
import config
import machine
import pin_server_controller
import server
import status_server_controller
import temperature_sensor
import utils

utils.printLog("NODEMCU", "rstrip boot up")

_temperature_sensor = temperature_sensor.TemperatureSensor(
    machine.Pin(config.D6))


def timeout1minute(timer):
    _temperature_sensor.update()
    _temperature_sensor.upload()


def timeout10minutes(timer):
    utils.syncDatetime()


tim0 = machine.Timer(0)
tim0.init(period=60000, mode=machine.Timer.PERIODIC, callback=timeout1minute)
tim1 = machine.Timer(1)
tim1.init(period=600000,
          mode=machine.Timer.PERIODIC,
          callback=lambda t: timeout10minutes())
timeout1minute(None)
timeout10minutes(None)
예제 #3
0
import config
import machine
import server
import status_server_controller
import temperature_sensor
import thermostat_server_controller
import utils

utils.printInfo("THERMOSTAT", "boot up")
utils.createSyncDateTimeTimer()
_temperature_sensor = temperature_sensor.TemperatureSensor(machine.Pin(config.DS18B20_PIN))
_relay_pin = machine.Pin(config.THERMOSTAT_RELAY_PIN, machine.Pin.OUT)
_switch_pin = machine.Pin(config.THERMOSTAT_SWITCH_PIN, machine.Pin.IN)
_led_pin = machine.Pin(config.THERMOSTAT_LED_PIN, machine.Pin.OUT)
_thermostat_server_controller = thermostat_server_controller.ThermostatServerController(_temperature_sensor, _relay_pin, _switch_pin, _led_pin)
_controllers = [_thermostat_server_controller]
_statusController = status_server_controller.StatusServerController('Thermostat', _controllers)
_server = server.Server(config.SERVER_PORT, _controllers + [_statusController])

try:
    _server.run()
except KeyboardInterrupt:
    utils.printInfo("THERMOSTAT", "stopped by the user")
    utils.deleteTimers()
except Exception as e:
    utils.printWarn("THERMOSTAT", "exception during server run: %s" % e)
    machine.reboot()
예제 #4
0
#Getting the ipv6 address and the port that will be used by the control server
SERVER_IP = sys.argv[1]
SERVER_PORT = int(sys.argv[2])

#Setting the port on which the mote are listening
MOTE_PORT = 8765

#Creating the socket of the server
serverSocket = socket.socket(family=socket.AF_INET6, type=socket.SOCK_DGRAM)
serverSocket.bind((SERVER_IP, SERVER_PORT))

#################################################################
#Registering the mote with their ipv6 address, edit if necessary#
#################################################################
temperature_mote = temperature_sensor.TemperatureSensor(
    "bbbb::c30c:0:0:1", MOTE_PORT)
mote_list.append(temperature_mote)
mote_ipv6[temperature_mote.ipv6] = mote_list.index(temperature_mote)

humidity_mote = humidity_sensor.HumiditySensor("bbbb::c30c:0:0:2", MOTE_PORT)
mote_list.append(humidity_mote)
mote_ipv6[humidity_mote.ipv6] = mote_list.index(humidity_mote)

detection_mote = motion_detector.MotionDetector("bbbb::c30c:0:0:3", MOTE_PORT)
mote_list.append(detection_mote)
mote_ipv6[detection_mote.ipv6] = mote_list.index(detection_mote)

alarm_mote = alarm.Alarm("bbbb::c30c:0:0:4", MOTE_PORT)
mote_list.append(alarm_mote)
mote_ipv6[alarm_mote.ipv6] = mote_list.index(alarm_mote)
###############################################################
예제 #5
0
        resources.base_url,
        coordinate_web_ids.x_web_id)
    part3.update_af_attribute(
        position_y,
        resources.base_url,
        coordinate_web_ids.y_web_id)

    # (Here, we retrieve the WebId for the Temperature attribute):
    value_web_id = helpers.get_attribute_web_id_by_name(
        "Temperature",
        resources.base_url,
        helpers.get_web_id(element_response))

    # Finally, we read the temperature from the temperature sensor, and POST
    # the value to the PI Point:
    sensor = temperature_sensor.TemperatureSensor()
    while True:
        current_temperature = sensor.read_temp()
        print("Sending:  " + str(current_temperature))
        part4.post_pi_value(
            current_temperature,
            pipoint_web_id,
            resources.base_url)
        print("Received: " + str(helpers.get_attribute_field(
            value_web_id,
            lambda x: x["Value"])))
        time.sleep(5)