Micropython Mqtt Streamer
Hello everyone, I have developed a micropython code to stream accelerometer data over mqtt. Also I have created a tool to visualize the data which is transferred from remote MQTT device which is executing micropython code.
Demo
Development
The first thing which I tried with micropython is connecting ESP8266 to a WiFi. I have tried the following script which I found from the official documentation of the micropython.
|
|
The wifi ip of the module can be examined with wlan.ifconfig()
command. I should say that scripting with a microcontoller is quite fun. ESP8266 was connected over usb over Uart line to my computer and I can scripting using micropython shell. For example: I have used upip module to install umqtt.simple
upython module to my ESP8266. After installing the umqtt module, I have tested its basic examples and they worked without any problem.
|
|
Next phase is reading data from accelerometer. I have used MPU6050 as the IMU sensor. It consists a gyro and an accelerometer sensor. I have used i2c scanner example code to detect the i2c address of the device. The address of my MPU6050 is 0x68
.
|
|
The following class is developed to read sensor values directly from MPU6050.
|
|
Main loop is also quite strait-forward. It read samples from acc and send these over mqtt protocol directly to the server.
|
|
The code can be reached from this github repo.