Displaying temperature on the STM32L4 Discovery Kit Board

0

I am able to send messages from the the STM32L4 Discovery Kit Board to the AWS Cloud as I have gone through the fist steps guide https://docs.aws.amazon.com/freertos/latest/userguide/freertos-prereqs.html. Although now I would like to display sensor data specifically temperature from the board to the cloud, how can I do this?

Obinex
asked 2 years ago259 views
1 Answer
0
Accepted Answer

Hi Obinex. You can use the functions in the BSP to access the sensor data. Then construct a JSON document to publish.

The demo you've been using publishes a plaintext message here: https://github.com/aws/amazon-freertos/blob/main/demos/coreMQTT/mqtt_demo_mutual_auth.c#L981-L993

You can find the BSP drivers for the various sensors here: https://github.com/aws/amazon-freertos/tree/main/vendors/st/stm32l475_discovery/BSP/B-L475E-IOT01

So you want some code like this to create a JSON document instead of a plaintext string:

        int16_t accel[3], magneto[3];
        float gyro[3];
        BSP_ACCELERO_AccGetXYZ(accel);
        BSP_GYRO_GetXYZ(gyro);
        BSP_MAGNETO_GetXYZ(magneto);

        ++publishCount;

        snprintf(publishPayload, sizeof(publishPayload), "{\"sequence\":%ld"
            ",\"payload\": {"
            "\"temperature\":%.2f"
            ",\"humidity\":%.2f"
            ",\"pressure\":%.2f"
            ",\"accelerometer\":{\"x\":%d,\"y\":%d,\"z\":%d}"
            ",\"gyroscope\":{\"x\":%.2f,\"y\":%.2f,\"z\":%.2f}"
            ",\"magnetometer\":{\"x\":%d,\"y\":%d,\"z\":%d}"
            "}}",
               publishCount,
               BSP_TSENSOR_ReadTemp(),
               BSP_HSENSOR_ReadHumidity(),
               BSP_PSENSOR_ReadPressure(),
               accel[0], accel[1], accel[2],
               gyro[0], gyro[1], gyro[2],
               magneto[0], magneto[1], magneto[2]
               );

If you are asking how to display it in the cloud, I suggest you read the following blog. Pattern 4 is one of the simplest ways to get started.

https://aws.amazon.com/blogs/iot/7-patterns-for-iot-data-ingestion-and-visualization-how-to-decide-what-works-best-for-your-use-case/

profile pictureAWS
EXPERT
Greg_B
answered 2 years ago
  • In the code above, what file would I put that code in?

  • Well the demos are just demos. You could certainly modify the MQTT mutual auth demo to publish that instead of "Hello World!". That's only an example snippet though to illustrate the concept.

  • I went to the link but I'm still not sure what to do, by the way this project is for my Final Year Project 2 for university.

  • The mutual auth demo sends the string defined by mqttexampleMESSAGE. At the most basic level you would replace that string with the JSON document created by the quoted fragment.

  • Ok, but from the code provided above where would I find "publishPayload" and "publishCount" those variables are not initialized. Also does that code need to be put in a function so the function can then be called by mqttexampleMESSAGE?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions