cancel
Showing results for 
Search instead for 
Did you mean: 

How to read Sensor data from STM32U5 ( B-U585IOT02A )

radeshsharma
Associate II

Hello community,

I've B-U585IOT02A. I want to use sensor values from it to my application running on node.js. I think to import those sensor values to application over the local network using mqtt. But as their is already a web-server installed in B-U585IOT02A . So I found that I can access sensor values after runing web-server at:

For example web-server is live at my local wifi ip : 192.168.1.33

192.168.1.33/Read_Temperature for temperature

192.168.1.33/Read_Humidity for humidity

192.168.1.33/Read_Pressure for Pressure

So I try to fetch directly these urls but fails these response are header less response.

So they didn't work with fetch, axios or https, even not with curl.

But these seems to be working in browser so I tried a trick to get data, I used header-less browser or we can say virtual browser to access the data.

The code by which I able to read data:

const puppeteer = require('puppeteer');
Read_Sensors();
function Read_Sensors(){
	(async () => {
      try {
        const browser = await puppeteer.launch();
        const [page] = await browser.pages();
		
		
		//Read Temperature
        await page.goto('http://192.168.1.33/Read_Temperature', { waitUntil: 'networkidle0' });
        const data = await page.evaluate(() => document.querySelector('pre').innerHTML);
		
		//Read Pressure
		await page.goto('http://192.168.1.33/Read_Pressure', { waitUntil: 'networkidle0' });
        const data2 = await page.evaluate(() => document.querySelector('pre').innerHTML);
		
		//Read Humidity
		await page.goto('http://192.168.1.33/Read_Humidity', { waitUntil: 'networkidle0' });
        const data3 = await page.evaluate(() => document.querySelector('pre').innerHTML);
		
        console.log("Temperature :" + data);
		console.log("Pressure :" + data2);
		console.log("Humidity :" + data3);
 
        await browser.close();
      } catch (err) {
        console.error(err);
      }
    })();
}

Here I'm using puppeteer package which use chromium in background which use 200mb of data, which we can say not a stable method.

So any on can suggest me a way another than this to read data from B-U585IOT02A by mqtt or another way directly to application.

Thanks in advance for you valuable answer.

2 REPLIES 2
Mohamed Aymen HZAMI
ST Employee

Hello @radeshsharma​  and welcome to the community,

You can use the Firmeware example under this path:

STM32Cube\Repository\STM32Cube_FW_U5_V1.1.0\Projects\B-U585I-IOT02A\Examples\BSP

This example cover all the sensors presented on the board

Mohamed Aymen

radeshsharma
Associate II

Thanks for reply @Mohamed Aymen HZAMI​ I was able to get sensors output using BSP Drivers but the issue I'm facing is that I want to send this all the sensors output to the mqtt broker running on my local machine our local internet connection.

I tried below example:

https://github.com/STMicroelectronics/STM32CubeU5/tree/main/Projects/B-U585I-IOT02A/Applications/NetXDuo/Nx_MQTT_Client

But this application is using tls by default I tried to change port to non-tls and tried to run it for local server but it not seems to work for local ip.

Do you have any example which show how to publish data to local mqtt broker.

Thanks in advance for you valuable answer.