We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Error: awk: cmd. line:1: Unexpected end of string



  • I want to write down the temperature from the DS18B20 sensor in the variable temp. I'm using the module os.popen, but I get an error awk: cmd. line:1: Unexpected end of string.

    import os
    
    temp = os.popen('''awk -F= '/t=/ {printf "%.03f\n", $2/1000}' /sys/devices/w1_bus_master1/28-0000053f7e76/w1_slave ''').readline()
    
    print(temp)
    


  • @CAP-33 said in Error: awk: cmd. line:1: Unexpected end of string:

    DS18B20

    Here are a few ideas/questions. As I'm not a popen() expert I am admittedly grasping at straws a little here. However it may help you think through the problem.

    Is the displayed the entire program file? It doesn't have a line #1 that invokes the proper interpreter.

    I was going to check one of my systems for the presence of file /sys/devices/w1_bus_master1/28-0000053f7e76/w1_slave. Unfortunately all three of my devices that were on line a bit ago have gone away and I am remote from them. Check to make sure the file exists.

    The final readline() method call may be a clue. Everything inside the popen() call is a single mandated parameter. There are optional parameters (https://www.tutorialspoint.com/python/os_popen.htm). One of the optional parameters can specify the use of line buffering. Perhaps you need to specify this parameter.

    take care!
    Bill



  • @William-Scott
    I do not know how right this is, but it works:

    import os
    
    def temp(temp):
    	
    	temp = os.popen('cat /sys/devices/w1_bus_master1/28-0000053f7e76/w1_slave').readlines()
    	
    	temp = temp[1]
    	
    	temp = temp[29:34]
    	
    	temp = int(temp)
    	
    	temp = round(temp / 1000, 1)
    
            print('Temperature :', temp)
    
    temp(temp)
    

    Just for some reason, rounding does not work


Log in to reply
 

Looks like your connection to Community was lost, please wait while we try to reconnect.