Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:04:55+00:00 2026-06-14T20:04:55+00:00

I have a USB temperature logger that uploads to Cosm every 30 seconds. The

  • 0

I have a USB temperature logger that uploads to Cosm every 30 seconds. The issue I’m having is that every 5 minutes, when I run the command it reports a text error instead of a number.

So I’m trying to figure out a way to get it to either loop until it receives a number or just ignore the text and resume the script (it quits with an error otherwise).

My very inelegant solution is to do this:

  # convert regular error message to number
    if temp_C == "temporarily": # "temporarily" is used as it happens to be the 4th word in the error message
            temp_C = 0.0

The current body of code is:

while True:
    # read data from temper usb sensor
    sensor_reading=commands.getoutput('pcsensor')

    #extract single temperature reading from the sensor

    data=sensor_reading.split(' ') #Split the string and define temperature
    temp_only=str(data[4]) #knocks out celcius reading from line
    temp=temp_only.rstrip('C') #Removes the character "C" from the string to allow for plotting

    # calibrate temperature reading
    temp_C = temp

    # convert regular error message to number
    if temp_C == "temporarily":
            temp_C = 0.0

    # convert value to float
    temp_C = float(temp_C)

    # check to see if non-float
    check = isinstance(temp_C, float)

    #write out 0.0 as a null value if non-float
    if check == True:
            temp_C = temp_C
    else:
            temp_C = 0.0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:04:56+00:00Added an answer on June 14, 2026 at 8:04 pm

    In Python, it is often easier to ask for forgiveness than permission (EAFP). When you encounter a ValueError, continue to the next iteration:

    try:
        temp_C = float(temp_C)
    except ValueError:
        continue # skips to next iteration
    

    Or more compactly (consolidating most of your function):

    try:
        temp_C = float(sensor_reading.split(' ')[4].rstrip('C'))
    except (ValueError, IndexError):
        continue
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a USB HID scale that I need to fetch the weighing reports
I have a D-Link DWM-156 3G USB modem that I want to send AT-commands
I have a temperature sensor, which is connected using an USB-I2C adapter ( http://www.robot-electronics.co.uk/htm/usb_i2c_tech.htm
I have a USB device that I need to be able to talk to
I have one USB stick having FAT32 type file system.I really in need to
I have a 1-Wire USB adapter (that bluish one) and wanted to use it
The instruments that are used with Guitar Hero and Rock Band have USB connections.
I have a usb device that is supposed to send a number when queried.
I have a USB weighing scale that I'm trying to import the reading into
I have a USB device that can move along a linear axis, stop at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.