Exemplo n.º 1
0
import settings
import time
import json
from urllib.request import urlopen
from urllib.parse import urlencode
from pyRF24 import pyRF24

radio = pyRF24("/dev/spidev0.0", 8000000, 25, retries = (15, 15), channel = settings.channel, dynamicPayloads = True, autoAck = True, ackPayload = True)
radio.openWritingPipe(settings.writing_pipe)
radio.openReadingPipe(1, settings.reading_pipe)
radio.printDetails()

radio.startListening()
while True:
  while radio.available():
    # read events from arduino
    len = radio.getDynamicPayloadSize()
    payload = radio.read(len)[:len].split()
    print("Received: ", payload)
    if payload[0] not in (b'COOLED', b'COOL', b'BURN', b'BURNED'): continue

    # send events to server, and receive any commands returned
    data = urlencode({'event': payload[0].lower(), 'timestamp': payload[1]}).encode("utf-8")
    cmds = []
    try:
      result = urlopen(settings.server_event_url, data).read().decode('utf-8')
      cmds = json.loads(result)
      print("Commands: ", cmds)
    except Exception as err:
      print("Report to server failed: ", err)
Exemplo n.º 2
0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from pyRF24 import pyRF24
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0E2]
radio = pyRF24("/dev/spidev0.0",
               8000000,
               18,
               retries=(15, 15),
               channel=76,
               dynamicPayloads=True,
               autoAck=True)
radio.openWritingPipe(pipes[0])
radio.openReadingPipe(1, pipes[1])
radio.printDetails()
message = input("Message: ")
while message:
    if radio.write(message):
        print("Sent", message)
    message = input("Message: ")
Exemplo n.º 3
0
from urllib import request

credentials = []

for line in open("credentials.txt", "r"):
    credentials.append(line.split("\n")[0])

db = mysql.connector.connect(
    user=credentials[1], password=credentials[2], host=credentials[0], database=credentials[3], autocommit=True
)
cur = db.cursor()

# gc = gspread.login(credentials[4], credentials[5])
# ws = gc.open("Heating Data").sheet1

radio = pyRF24("/dev/spidev0.0", 8000000, 18, retries=(15, 15), channel=76, dynamicPayloads=True, autoAck=True)
pipes = [0xF0F0F0F0E1, 0xF0F0F0F0E2]
radio.openWritingPipe(pipes[0])
radio.openReadingPipe(1, pipes[1])

last_threshold = {
    "0": [
        None,
        None,
        None,
        None,
        None,
        None,
        None,
        None,
        None,
Exemplo n.º 4
-1
	def __init__(self):
		threading.Thread.__init__(self)
		self.running = True

		# Setup Radio
		self.pipes = [0xF0F0F0F0E1, 0xF0F0F0F0E2]
		self.radio  = pyRF24("/dev/spidev0.0", 8000000, 18, retries = (15, 15), channel = 76,
			dynamicPayloads = True, autoAck = True)
		self.radio.openWritingPipe(self.pipes[0])
		self.radio.openReadingPipe(1, self.pipes[1])
		self.reading_channel = 76
		self.writing_channel = 78
		self.radio.printDetails()