RoueSA
RoueSA

Reputation: 13

Change MySQL data received from sensor

I receive data from a Bluetooth sensor via an ESP32 which then sends data to raspberry pi via API to MySQL. I receive the temperature on the rpi, but as 1230 instead of 12.30. Is it possible to change it in MySQL, if yes, how?

Upvotes: 1

Views: 39

Answers (1)

Lars Skaug
Lars Skaug

Reputation: 1386

select 1230/100 will return 12.3

Do the following if you want two decimal points:

select format(temperature/100, 2)
from table1

To use this, you may want to create a view that has this calcuated field in it. You would then use the view instead of the table in your API.

create view view1 as (select format(temperature/100, 2) 
                      from table1);

You can see how it works in Fiddle.

Upvotes: 1

Related Questions