Race condition in Berry?

43 views
Skip to first unread message

R Casorso

unread,
Feb 5, 2025, 5:55:46 PMFeb 5
to TasmotaUsers
Just trying out Berry on a ESP32 and ran into something that I don't understand.  In the following code, if I remove the print statement it fails saying that value is nil however with the print statement it works every time.  I'm thinking it might be a race condition but that doesn't make any sense.  Any ideas?
        var js = json.load(tasmota.read_sensors(true))

        value = js[self.sensorId]['Temperature']
        print(value)
        if value != nil

Thanks

Philip Knowles

unread,
Feb 6, 2025, 10:46:00 AMFeb 6
to R Casorso, TasmotaUsers
Maybe try var value = js[self.semsorId]['Temperature']
Just in case


From: sonof...@googlegroups.com <sonof...@googlegroups.com> on behalf of R Casorso <rvca...@gmail.com>
Sent: 05 February 2025 22:55
To: TasmotaUsers <sonof...@googlegroups.com>
Subject: Race condition in Berry?
 
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/sonoffusers/11cc7da3-5a88-4cae-8be2-b38ce4be27d6n%40googlegroups.com.

Stephan Hadinger

unread,
Feb 6, 2025, 11:25:00 AMFeb 6
to Philip Knowles, R Casorso, TasmotaUsers
Can you paste the complete code and error messages?

The code here surely does not compile. Why is the 'if' at the end?

Le 6 févr. 2025 à 16:45, Philip Knowles <knowles...@gmail.com> a écrit :



R Casorso

unread,
Feb 6, 2025, 1:18:47 PMFeb 6
to TasmotaUsers
thanks for the feedback  here is the complete function.  It is called every X seconds.  like this it works but if I comment out the print if fails with 
19:17:18.061 BRY: Exception> 'attribute_error' - the 'map' object has no method '()'

def extractSensors()
        var value
        var js = json.load(tasmota.read_sensors(true))

        value = js[self.sensorId]['Temperature']
        print("") #needs a delay here????
        if value != nil
            for  x: 0.. self.IntegrateLen - 1 # move the buffer down one
               
                self.temperatures[self.IntegrateLen -x] = self.temperatures[self.IntegrateLen -x-1]
                #print (x, self.temperatures[self.IntegrateLen -x] )
            end
           
            self.temperatures[0] = real(value) # set the last reading
               # print("extract sensor:",self.temperature[0])  
                 
            if self.mqtt_up
                mqtt.publish("stat/"+self.topic+"/"+self.sensorId,str(self.temperature))
            end
        end
    end

Stephan Hadinger

unread,
Feb 6, 2025, 2:27:02 PMFeb 6
to R Casorso, TasmotaUsers
Thanks. It's definitely not a race condition because everything is sequential in Berry. 
However I suspect a compiler bug. I had already similar miscompilation in the past. 

I'm off this week but will try to debug this next week. Your code is straightforward and I thought we got rid of all those compilation bugs. 

Stay tuned. 


(sent from a tiny keyboard)

Le 6 févr. 2025 à 19:18, R Casorso <rvca...@gmail.com> a écrit :

thanks for the feedback  here is the complete function.  It is called every X seconds.  like this it works but if I comment out the print if fails with 
--
You received this message because you are subscribed to the Google Groups "TasmotaUsers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonoffusers...@googlegroups.com.

Stephan Hadinger

unread,
Feb 9, 2025, 1:15:48 PMFeb 9
to TasmotaUsers
Hi, I confirm this is a compiler bug. I will work on it.

Thanks for reporting this problem.

Stephan Hadinger

unread,
Feb 12, 2025, 4:38:38 PMFeb 12
to TasmotaUsers
It is now fixed in the latest Tasmota version. Thanks for reporting this bug.
Reply all
Reply to author
Forward
0 new messages