Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to convert int to string?

I need to prepare a request string for Thingspeak MQTT API. The content of the published message needs to follow old Thingspeak GET request rules:
"field1=123&field2=332&field3=222"
I want to fill the numeric part with values returned from mJS calls - for example, ADC.read(36), or ESP32.temp() - those calls return FFI-ed int's.
Implicit conversion fails with error, ESP32.temp().toString() also does not work.
So I have no idea how to achieve this in the JS code. The only way that I see now is to create new C FFI functions that returns "char*" results - so I could make the conversion in the C using sprintf() or friends.
Is there something that I am missing? Maybe this could be achieved in some JS API lib, liks "string_utils.js" - but I am not that good at JS to create one myself.

Comments

Sign In or Register to comment.