@ryan.j.mortenson (Ryan J Mortenson) posted a new topic, subject "No historical data with Bring Your Own Thing". It read:

   I am working on a project using a RPi Version 3 Model B V1.2 device and the Bring Your Own Thing set up. The RPi is pulling some data from sensors (Temperature and Soil Moisture) via BTLE and pushing the data using the Python CayenneMQTTClient. I don't seem to get any historical data. I get instantaneous data and can view the latest data in the widgets.
    
    Here is my set up:  
    client = cayenne.client.CayenneMQTTClient()  
    client.on_message = on_message  
    client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
    [code] 
        while True:
            client.loop()
            sleep(30)
        
    [/code]
    
    Here are the two writes:  
    client.celsiusWrite(addr + " TEMP", float(temp)/float(1000))  
    client.virtualWrite(addr + " MOISTURE", (float(soil)/float(4096) * 100), “Soil Moisture”, “%”)
    
    The following image is my dashboard no data in graphs but data in widgets:  
    
    
    nohistoricaldata1919×1006 280 KB
    
    From the Data tab using Live data query:  
    
    
    livedata1919×910 71.1 KB
    
    Switching to the Minute query:  
    
    
    nominutedata1924×912 54.9 KB
    
    Any help would be greatly appreciated.

After which, @Agroelektronik (Agroelektronik) added

    If device is conected moments ago, it takes time to gather statistic.

So @jcruz (Jesse Cruz) replied

    Hi @ryan.j.mortenson,
    
    Would you mind sharing the code you're using?
    
    Thanks.  
    -Jesse

Then @ryan.j.mortenson (Ryan J Mortenson) said

    I left the device running overnight collecting data approximately every 30 seconds.

After which, @ryan.j.mortenson (Ryan J Mortenson) added

    Requested Code:
    [code] 
        import argparse
        import logging
        import sys
        import threading
        import cayenne.client
        import traceback
        
        from bluepy import btle
        from time import sleep
        
        NAME_DESCRIPTOR = "Complete Local Name"
        NAME = "Empty Example"
        
        MQTT_USERNAME  = ""
        MQTT_PASSWORD  = ""
        MQTT_CLIENT_ID = ""
        
        CHAR_TEMP_UUID = ""
        CHAR_SOIL_MOISTURE_UUID = ""
        
        log = None
        client = None
        
        def handle_device_connection(addr):
            log.info("Attempting to connect to: {}".format(addr))
            try:
                dev = btle.Peripheral(addr)
            except Exception as e:
                log.error("Could not connect to device: {}".format(addr))
                return
        
            try:
                temp_char = dev.getCharacteristics(uuid=CHAR_TEMP_UUID)[0]
                soil_char = dev.getCharacteristics(uuid=CHAR_SOIL_MOISTURE_UUID)[0]
                temp = int(temp_char.read()[-8b7c:f320:99b9:690f:4595:cd17:293a:c069-1].encode("hex"), 16)
                soil = int(soil_char.read()[-8b7c:f320:99b9:690f:4595:cd17:293a:c069-1].encode("hex"), 16)
                client.celsiusWrite(addr + " TEMP", float(temp)/float(1000))
                client.virtualWrite(addr + " MOISTURE", (float(soil)/float(4096) * 100), "Soil Moisture", "%")
                log.info(temp)
                log.info(soil)
                dev.disconnect()
            except Exception as e:
                log.error("Lost connection")
                log.error(traceback.format_exc())
        
        class ScanPrint(btle.DefaultDelegate):
        
            def __init__(self):
                btle.DefaultDelegate.__init__(self)
        
            def handleDiscovery(self, dev, isNewDev, isNewData):
                scan_data = dev.getScanData()
                for (sdid, desc, val) in scan_data:
                    if desc == NAME_DESCRIPTOR and val == NAME:
                        log.info("Found device {} reading values".format(dev.addr))
                        t = threading.Thread(target=handle_device_connection, args=(dev.addr, ))
                        t.start()
        
        def on_message(message):
              print("message received: " + str(message))
        
        if __name__ == "__main__":
            parser = argparse.ArgumentParser()
            parser.add_argument("--verbosity", "-v", type=str, choices=["DEBUG", "INFO"],
                 default="INFO", help="Level of verbosity")
            args = parser.parse_args()
        
            FORMAT = '[%(asctime)s %(filename)15s line: %(lineno)5s] %(message)s'
            logging.basicConfig(stream=sys.stdout, format=FORMAT, level=getattr(logging, args.verbosity))
            log = logging.getLogger("ble_test")
        
            client = cayenne.client.CayenneMQTTClient()
            client.on_message = on_message
            client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID)
        
            while True:
                client.loop()
                log.info("Starting Scan...")
                scanner = btle.Scanner(0).withDelegate(ScanPrint())
                devices = scanner.scan(30)
                log.info("Scan Complete, sleeping for 30 seconds")
                sleep(30)
        
    [/code]

After which, @asanchezdelc (Adrian Sanchezdelc) added

    ryan.j.mortenson:
    
    > celsiusWrite
    
    Hi @ryan.j.mortenson,
    
    client.celsiusWrite(CHANNEL, VALUE) <— CHANNEL must be an integer.

So @ryan.j.mortenson (Ryan J Mortenson) replied

    Worked like a charm, thank you.


{'source': 'discourse', 'url': 'https://community.mydevices.com/t/no-historical-data-with-bring-your-own-thing/8420', 'title': 'No historical data with Bring Your Own Thing', 'views': 1302, 'has_accepted_answer': False, 'word_count': 519, 'like_count': 3, 'reply_count': 4, 'participant_count': 4, 'posts': 7, 'tags': '', 'author': '@ryan.j.mortenson (Ryan J Mortenson)', 'participants': '@ryan.j.mortenson (Ryan J Mortenson), @Agroelektronik (Agroelektronik), @jcruz (Jesse Cruz), @asanchezdelc (Adrian Sanchezdelc)', 'image_url': ['https://global.discourse-cdn.com/business5/uploads/mydevices/optimized/2X/1/18d541f3645b869539234aaa6b4417fd12632ea4_2_1023x536.jpg'], 'created_at': '2018-03-05T14:21:08.516Z', 'last_posted_at': '2018-03-06T03:55:50.488Z'}