Help with mqtt servo control

Hi,

I'm trying to get a JSON message sent from amazon AWS to control the position of a servo.

my goal is to be able to turn a JSON like this:
image

into usable variables in the device like this:
image

i.e
image

image

I am using the AWS_IoT_WiFi example in GitHub - arduino/ArduinoCloudProviderExamples: Examples of how to connect various Arduino boards to cloud providers.

I'm wondering if anyone has had any success with getting values parsed from a json sent over mqtt and populated into usable variables. I'm using a Nano 33 IoT.

The ArduinoJson library claims to be able to do that, but I feel that I am not grasping the concepts well enough to apply it correctly.

I am able to read the contents of the message using:
image

but I would like to be able to expand on this and parse the JSON to extract the information, but I'm stuck.

I think I'm having conversion trouble. If there is an easier way of doing this please let me know. I'm open for options.

I'm probably not the best person to help with this, but I'm currently working on a project that filters MQTT messages.

Can you put the message you are getting form the serial monitor when an MQTT comes in?

Hi, thanks for getting back to me.

This is what I get when I send that test JSON from AWS.

image

And this is the function that is called when the MQTT comes in.

image

...as expected.

The issue I have is when I'm trying to implement the ArduinoJson.h:

image

There's something in my understanding that I'm missing. I tried to effectively replicate what was in one of the examples but it doesn't seem to be compatible with what I am trying to do.

In the example, they 'provide' the json[] for it to deserialise.... You can see how I've tried to replace the json in the example with (char)mqttClient.read(); and hoped it would work(?). I think I need to understand what I'm missing and why that can't be done.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.