0

error detection and resolution
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

error detection and resolution

by Rcayot on Sun Mar 07, 2021 5:46 pm

I recently posted a success for sending bme280 sensor data to a Pi Zero W via BLE and to AIO via wifi. The system works well, but the aio occasionally sends back an error of "missing required value". In a previous invocation of this app, I found that (I think) a void string was beinjg sent, or read. So I did some things to try to control when teh sends and reads happen.

So, here is a snippet:
Code: Select all | TOGGLE FULL SIZE
def get_and_send_temperature():
    s = "bme280.temperature"
    uart_service.write(s.encode("utf-8"))
    uart_service.write(b'\n')
    temperature = uart_service.readline().decode("utf-8")
    print(temperature)
    aio.send(temperature_feed.key, str(temperature))


That sends a string "bme280.temperature" which the reciever reads in the following snippet:
Code: Select all | TOGGLE FULL SIZE
while ble.connected:
        s = uart.readline()
        if s:
            try:
                result = (eval(s))
            except Exception as e:
                result = repr(e)
            uart.write(str(result))


The string is recieved and then evaluated, which returns the temperature data, which is then written out to the UART.


My question is, how do I verify that what is being written, or read actually contains the required string? In the last bit of code, there is a line:

Code: Select all | TOGGLE FULL SIZE
if s:


I was wondering if that meant "if the string s is not empty, or if string s contains something. If that is the case, then can I sue that as a test for the data before it is written or read? If there a better way to determine if the string contains what it is supposed to?

In my code on teh Pi Zero W, the data is 'printed' before sending to AIO, but whenever it 'faults' or crashes, there is no value printed (although it appears to contain a 'line feed' or 'new line' as a blank line appears before the error messages.

Anyway, see my previous post for teh whole code if you need it, please if you have a suggestion, please by all means post it for me.

Roger Ayotte

Rcayot
 
Posts: 137
Joined: Sat Feb 08, 2020 6:48 pm

Re: error detection and resolution

by brubell on Mon Mar 15, 2021 9:56 am


brubell
 
Posts: 1319
Joined: Fri Jul 17, 2015 10:33 pm

Re: error detection and resolution

by brubell on Mon Mar 15, 2021 9:56 am


brubell
 
Posts: 1319
Joined: Fri Jul 17, 2015 10:33 pm

Please be positive and constructive with your questions and comments.