示例#1
0
    def get(self, key="", subkey=""):

        if (connect.do_connect()):

            print("Firebase")
            URL = const.FIREBASE_HOST + "/"

            if len(key) > 0:
                URL += key  #+ "/"
                if len(subkey) > 0:
                    URL += "/" + subkey

            URL += ".json"

            print(URL)

            try:
                response = requests.get(URL)
                print(response.status_code)
                #print(response.text)
                print("\r\n")
                text = response.text
                #response.close()
                return text
            except:
                print("ERROR!!!")
示例#2
0
def set(Key, Value):
    if (connect.do_connect()):

        print("Firebase")
        URL = const.FIREBASE_HOST

        if '.firebaseio.com' not in URL.lower():
            if '.json' == URL[-5:]:
                URL = URL[:-5]
            if '/' in URL:
                if '/' == URL[-1]:
                    URL = URL[:-1]
                URL = 'https://' + \
                      URL.split('/')[0] + '.firebaseio.com/' + URL.split('/', 1)[1] + '.json'
            else:
                URL = 'https://' + URL + '.firebaseio.com/.json'
            return URL

        if 'http://' in URL:
            URL = URL.replace('http://', 'https://')
        if 'https://' not in URL:
            URL = 'https://' + URL
        if '.json' not in URL.lower():
            if '/' != URL[-1]:
                URL = URL + '/.json'
            else:
                URL = URL + '.json'

        data = {Key: Value}
        response = requests.patch(URL, data=json.dumps(data))
        #print(response.status_code)
        #print(response.text)
        print("\r\n")

        return response.text
示例#3
0
def Telegram_get():
    global update_id

    if (connect.do_connect()):

        s = _socket.socket()

        ai = _socket.getaddrinfo(const.TELEGRAM_API, const.TELEGRAM_PORT)
        print("Address infos:", ai)
        addr = ai[0][-1]

        #s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        print("Connect address:", addr)
        print("Telegram")
        s.connect(addr)

        s.settimeout(3.0)

        s = ssl.wrap_socket(s)
        print(s)
        print("\r\n")

        getRequest = "GET /bot"
        getRequest += const.TELEGRAM_TOKEN
        getRequest += "/getUpdates"
        getRequest += "?"
        getRequest += "&limit=1"
        getRequest += "&timeout=100"
        getRequest += "&offset=" + update_id
        getRequest += " HTTP/1.0\r\n\r\n"
        #getRequest +=
        s.write(getRequest)
        quote = s.read(4096)
        quote = quote.decode("ascii")
        #print(quote)
        #print("\r\n")
        if (len(quote) > 0):
            #print(quote)
            quote = quote[379:]
            retJson = json.loads(quote)
            print(retJson["result"])
            #print(retJson["result"][0]["update_id"])
            temp = retJson["result"][0]["update_id"]
            up_id = int(str(temp))
            print("up_id = " + str(up_id))
            up_id2 = int(str(update_id))
            print("up_id2 = " + str(up_id2))
            if (up_id >= up_id2):
                update_id = str(retJson["result"][0]["update_id"] + 1)
                print("Json update_id + 1 = " + update_id)
        else:
            print("Not message >> Last update_id = " + update_id)

        print("\r\n")
        s.close()
示例#4
0
def getMessage(messages):

    global update_id

    if (connect.do_connect()):

        s = _socket.socket()

        ai = _socket.getaddrinfo(const.TELEGRAM_API, const.TELEGRAM_PORT)
        #print("Address infos:", ai)
        addr = ai[0][-1]

        print("Connect address:", addr)
        print("Telegram")
        s.connect(addr)

        s.settimeout(const.TELEGRAM_TIMEOUT)

        s = ssl.wrap_socket(s)
        #print(s)
        print("\r\n")

        getRequest = "GET /bot"
        getRequest += const.TELEGRAM_TOKEN
        getRequest += messages
        getRequest += " HTTP/1.0\r\n\r\n"

        s.write(getRequest)
        quote = s.read(4096)
        #print(quote)
        #quote = quote.decode("ascii")
        #print(quote)
        #print("\r\n")
        #if (len(quote) > 0):
        #    #print(quote)
        #    quote = quote[379:]
        #    retJson = json.loads(quote)
        #    print(retJson["result"])
        #    #print(retJson["result"][0]["update_id"])
        #    temp = retJson["result"][0]["update_id"]
        #    up_id = int(str(temp))
        #    print("up_id = " + str(up_id))
        #    up_id2 = int(str(update_id))
        #    print("up_id2 = " + str(up_id2))
        #    if (up_id >= up_id2):
        #        update_id = str(retJson["result"][0]["update_id"] + 1)
        #        print("Json update_id + 1 = " + update_id)
        #else:
        #    print("Not message >> Last update_id = " + update_id)

        #print("\r\n")
        s.close()
        return quote
示例#5
0
def getMessages(messages):

    if (connect.do_connect()):

        s = _socket.socket()

        ai = _socket.getaddrinfo(const.TELEGRAM_API, const.TELEGRAM_PORT)
        #print("Address infos:", ai)
        addr = ai[0][-1]

        print("Connect address Telegram:", addr)
        s.connect(addr)

        s.settimeout(const.TELEGRAM_TIMEOUT)

        s = ssl.wrap_socket(s)
        #print(s)
        print("\r\n")

        getRequest = "GET /bot"
        getRequest += const.TELEGRAM_TOKEN
        getRequest += messages
        getRequest += " HTTP/1.0\r\n\r\n"

        s.write(getRequest)
        quote = s.read(4096)
        #print(quote)
        quote = quote.decode("ascii")
        #print(quote)
        #print("\r\n")
        if (len(quote) > 0):
            #print(quote)

            ind = quote.find("\r\n\r\n")
            quote = quote[ind:]
            quote = json.loads(quote)
            try:
                quote = quote["result"][0]
            except:
                quote = quote["result"]
        else:
            quote = "No Message"

        #print("\r\n")
        s.close()

        return quote
示例#6
0
def Firebase_get():
    #global update_id
    #update_id="423322083"

    if (connect.do_connect()):

        #s = _socket.socket()

        #ai = _socket.getaddrinfo(const.FIREBASE_HOST, const.FIREBASE_PORT)
        #print("Address infos:", ai)
        #addr = ai[0][-1]

        #s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

        #print("Connect address:", addr)
        print("Firebase")
        URL = const.FIREBASE_HOST
        #URL += "/" + const.FIREBASE_LEDSTATUS
        #URL += "/" + const.FIREBASE_LAST_MESSAGE

        print(URL)
        if '.firebaseio.com' not in URL.lower():
            if '.json' == URL[-5:]:
                URL = URL[:-5]
            if '/' in URL:
                if '/' == URL[-1]:
                    URL = URL[:-1]
                URL = 'https://' + \
                      URL.split('/')[0] + '.firebaseio.com/' + URL.split('/', 1)[1] + '.json'
            else:
                URL = 'https://' + URL + '.firebaseio.com/.json'
            return URL

        if 'http://' in URL:
            URL = URL.replace('http://', 'https://')
        if 'https://' not in URL:
            URL = 'https://' + URL
        if '.json' not in URL.lower():
            if '/' != URL[-1]:
                URL = URL + '/.json'
            else:
                URL = URL + '.json'

        response = requests.get(URL)
        print(response.status_code)
        print(response.text)
示例#7
0
    def set(self, key, value):

        if (connect.do_connect()):

            print("Firebase")
            URL = const.FIREBASE_HOST + "/"

            URL += ".json"

            print(URL)

            data = {key: value}
            response = requests.patch(URL, data=json.dumps(data))
            print(response.status_code)
            text = response.text
            #response.close()
            #print(.text)
            print("\r\n")

            return text
示例#8
0
    def get(self, Key=""):

        if (connect.do_connect()):

            print("Firebase")
            URL = const.FIREBASE_HOST
            if len(Key) > 0:
                URL += "/" + Key
            #print(URL)

            #URL = self.parseURL(URL)
            if '.firebaseio.com' not in URL.lower():
                if '.json' == URL[-5:]:
                    URL = URL[:-5]
                if '/' in URL:
                    if '/' == URL[-1]:
                        URL = URL[:-1]
                    URL = 'https://' + \
                          URL.split('/')[0] + '.firebaseio.com/' + URL.split('/', 1)[1] + '.json'
                else:
                    URL = 'https://' + URL + '.firebaseio.com/.json'
                return URL

            if 'http://' in URL:
                URL = URL.replace('http://', 'https://')
            if 'https://' not in URL:
                URL = 'https://' + URL
            if '.json' not in URL.lower():
                if '/' != URL[-1]:
                    URL = URL + '/.json'
                else:
                    URL = URL + '.json'

            response = requests.get(URL)
            #print(response.status_code)
            #print(response.text)
            print("\r\n")

            return response.text
示例#9
0

Where do voices come from?
https://evolution.voxeo.com/library/audio/prompts/numbers/index.jsp


"""

import machine
import math
import time
import connect
import ntptime
import machine

connect.do_connect(verbose=True)
ntptime.settime()

rtc = machine.RTC()

speakerpin = machine.Pin(25)

dac = machine.DAC(speakerpin)


def dacspeedtest():
    nomadcfreq = 8000
    duration = 1
    nomperiod_us = 1000000 // nomadcfreq
    nomaudiofreq = 1500
    bytes = bytearray([
示例#10
0
    while not RLY_STOP.value():
        if time.ticks_ms() >= entry + 500:
            RLY_STOP.value(1)

# move the door upwards
def lift_now():
    if not door_up:
      entry = time.ticks_ms()
      RLY_UP.value(0)
      while not RLY_UP.value():
          if time.ticks_ms() >= entry + 500:
              RLY_UP.value(1)

# Ready to hit the internet, find MQTT broker and do stuff

connect.do_connect() # run WiFi connect script
# credentials are externally stored


#  MQTT unique ID and creds to connect - credentials are externally stored
CLIENT_ID = ubinascii.hexlify(machine.unique_id()) # CLIENT_ID is unique & local


# a callback function to handle inbound MQTT messages
def sub_cb(topic, msg):
    print((topic, msg))
    global cmd_up
    global cmd_down
    if topic == b"otto/cmd": # this topic receives action commands
        if msg == b"up":
          button_A()
示例#11
0
    while lifting:  # Stop first if the door is lifting
        lifting = False  # Stopped lifting
        RLY_STOP.value(1)
        while RLY_STOP.value():
            if time.ticks_ms() >= entry + 500:
                RLY_STOP.value(0)
    while FOB_B.value() | cmd_down:
        lowering = True
        RLY_DOWN.value(1)
    while not FOB_B.value() | cmd_down:
        lowering = False
        RLY_DOWN.value(0)


# run WiFi connect script
connect.do_connect()

#  MQTT server and creds to connect
SERVER = "m20.cloudmqtt.com"
USER = "******"
PASSWORD = "******"
PORT = "XXXXX"
CLIENT_ID = ubinascii.hexlify(machine.unique_id())


def sub_cb(topic, msg):  # the callback to handle MQTT messages
    print((topic, msg))
    global cmd_up
    if topic == b"otto/cmd":
        if msg == b"up"
        cmd_up = True