-1

I am trying to send MPU9250 sensor data to Pubnub IOT platform using node mcu, but not able to do it since the sensor data is not in JSON format. I know about publishing string but don't know about variable.

About Pubnub Library - https://github.com/pubnub/arduino

This is the part which I need help in:-

IMU.readSensor();

PubNonSubClient *pclient = PubNub.publish(pubchannel, IMU.getAccelX_mss());

But above line has error so how do i send imu sensor data to pubnub? All connections are right and sensor is working since I tested it.

  • Have you tried enabling the debug option? To enable debug logging to the Arduino console, add #define PUBNUB_DEBUG before #include <PubNub.h> – VE7JRO Mar 5 at 20:27
  • format it in json before sending it out, for small payloads, hand-building JSON isn't that hard. – dandavis Mar 6 at 17:51
0

This is the format which helped me to upload the data successfully. I didn't knew what JSON format was and got stuck. In case if someone stumbles on a similar problem.

char buf[5] = {};

sprintf(buf, "\"%d\"", IMU.getAccelX_mss());

PubNonSubClient *pclient = PubNub.publish(pubchannel, buf);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.