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
已提问 2 年前268 查看次数
1 回答
0
已接受的回答

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
专家
Greg_B
已回答 2 年前
  • 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?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容