Sending values from arduino to raspberry pi to ubidots


#1

we tried this way to send multiple values to different dashboards, but the ELSE part in the program is not working.
What can be done for that purpose and if any other ways are there to do so,
help is appreciated

import serial

from ubidots import ApiClient
print("Program Started")
api = ApiClient(token ='A1E-dnrYvUK0A1e65ZJXS7SvJLOWvZzKet')
my_temp = api.get_variable('5a784be2c03f9727382ea6be')
rpm=api.get_variable('5a784bcbc03f9727192e4cfa')
while True:
   for i in range(2):
      if(i==0):i=i+1
      ser = serial.Serial('/dev/ttyACM0', 9600) #update with port for Arduino
   read_serial = ser.readline()
   tempReading =long(read_serial)
   new_value = my_temp.save_value({'value': tempReading})
   print(new_value)
else:ser = serial.Serial('/dev/ttyACM0', 9600) #update with port for Arduino
read_serial = ser.readline()
tempReading =long(read_serial)
new_value = rpm.save_value({'value': tempReading})
print(tempReading)


#2

Greetings @tushar07,

First than all you should try to send a fixed value, aka {'value' : 10} and see if you receive it properly, if yes, I believe that your issue may be related with a variable type and I would advise you to cast your temperature variable to float: {'value' : float(tempReading)}

Also, I see several indentation errors inside the while loop, please fix them too.

Regards