0
votes

I'm trying to convert this line of code :

array_of_power1.append(dict(measurement=topic_mqtt_power1,timestamp=int(epoch_time_stamp * 1000000000),fields=dict(power=power1),tags=dict(MachineType=Machine_type,MachineName=Machine_name)))

into

array_of_power1.append({'measurement' : 'topic_mqtt_power1', 'timestamp' : 'epoch_time_stamp' * 1000000000, fields: {'power' : 'power1'}, tags: {MachineType : Machinetype, MachineName : Machine_name}})

and I'm getting

Traceback (most recent call last): File "", line 1, in OverflowError: repeated string is too long

The reason why I'm changing from the dict struct to the other method is that the dict struct "dict()" doesnt work in micropython.

1
by writing 'epoch_time_stamp' * 1000000000 you are writing epoch_time_stamp 1000000000 time, remove the * - Matteo Peluso
makes sense now, thanks! the second problem i have is its showing "NameError: name 'fields' is not defined"? - resolver101

1 Answers

1
votes

You should run something like this to avoid the error of OverflowError and NameError :

array_of_power1.append({'measurement' : 'topic_mqtt_power1', 
                        'timestamp' : 'epoch_time_stamp x 1000000000',
                        'fields': {'power' : 'power1'}, 
                        'tags': {MachineType : Machinetype, MachineName : Machine_name}})