thingSpeak/ESP8266_convert Str=> Int
Posted: Tue Mar 19, 2019 6:05 am
Hello ,
I'm trying to create a code that allows me to send a specific values from a string and convert it to integer in order to display it in thingspeak charts but the problem that I keep receiving
my code is below :
So after executing this code I keep receiving
I'm trying to create a code that allows me to send a specific values from a string and convert it to integer in order to display it in thingspeak charts but the problem that I keep receiving
so mycode is below:Traceback (most recent call last)eError: can't convert 'int' object to str implicitly
Code: Select all
i2c = I2C ( scl = Pin(5) , sda = Pin(4))
accelerometer = mpu6050.accel(i2c)
r = accelerometer.get_values()
print (r)
What I tried to do is to extract a specific value from this result like this :Result : {'GyZ': 111, 'GyY': 90, 'GyX': -70, 'Tmp': 40.1535, 'AcZ': 10004, 'AcY': 692, 'AcX': -12728}
Code: Select all
k = (str(r['GyX']))
So now Itried to publish this values which is string and convert it into integer before publushing itresult : -70
my code is below :
Code: Select all
credentials = "channels/{:s}/publish/{:s}".format(THINGSPEAK_CHANNEL_ID, THINGSPEAK_CHANNEL_WRITE_API_KEY)
#T2 = [map(int, x) for x in r]
payload = "field1={:.1f}\n" + int(k)
client.publish(credentials, payload)
Anyone can light me on this ?Traceback (most recent call last)eError: can't convert 'int' object to str implicitly