예제 #1
0
def main():
    micropython.kbd_intr(-1)
    machine.UART(0, 9600).init(
        9600)  # 9600 baud rate recommended by LoLin NodeMcu board
    for line in sys.stdin:

        raw = line

        if not nic.isconnected():
            led.on()
            if not network.STAT_CONNECTING:
                nic.connect('bloomu')

        else:
            led.off()
            if gprmcREG.match(raw):
                raw = raw.split(',')
                raw.pop(0)
                dateTime = raw[8] + raw[0]
                dateTime = dateTime.replace('.', '')
                locData = {
                    "lat": raw[2] + raw[3],
                    "long": raw[4] + raw[5],
                    "speed": raw[6]
                }
                data = {dateTime: locData}
                urequests.patch(dataBaseURL,
                                data=json.dumps(data),
                                headers={"content-type": "application/json"})
                data = {dateTime: raw}
                urequests.patch(
                    "https://bloombus-163620.firebaseio.com/rawLog/.json",
                    data=json.dumps(data),
                    headers={"content-type": "application/json"})
예제 #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 patch(self, path, myJson):
     try:
         url = self.firebase + path + '.json' if self.auth == None else self.firebase + path + '.json?auth=' + self.auth
         response = urequests.patch(url, data=json.dumps(myJson))
         #return response
     except:
         print("PATCH Error?")
     try:
         response.close()
     except:
         print("Close Error?")
예제 #4
0
 def patch(self,path,myData):
     """
     this method put in a branch a Mydata just if a branch exist.
     myData = {key :value}
     path  = 'branch/'
     """
     if self.auth is None:
         try:
             response = urequests.patch(self.firebase+path+'.json', data = json.dumps(myData))
         except:
             print("erro")
     else:
         try:
             url = self.firebase+path+'.json?auth='+self.auth
             response = urequests.patch(url, data = json.dumps(myData))
         except:
             print("erro")
     try:
         response.close()
     except:
         print("erro")
예제 #5
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
def patch(URL, msg):
    to_post = json.dumps(msg)
    response = requests.patch(firebaseURL(URL), data=to_post)
    if response.status_code != 200:
        raise FirebaseException(response.text)
예제 #7
0
import urequests as requests
 def patch(self, msg, token):
     to_post = json.dumps(msg)
     request_ref = Database.build_request_url(self, token)
     response = requests.patch(request_ref, data=to_post)
     if response.status_code != 200:
         raise FirebaseException(response.text)