I have done this project for the Secure Everything with Azure Sphere contest, with the Azure Sphere MT3620 Starter Kit design by Avnet.
I used Visual Studio Code + Platformio with the plugin from Georgi Angelov. Here is the information to install it https://github.com/Wiz-IO/platform-azure
It has a lot of features, We are going to use in this project the M7 Core, one of the two M4 cores, two in built ADC, ADC0 to receive the ambient light and ADC1 to receive the signal from the analog multiplexer, Two GPIO pins to select the signal from the analog multiplexer and the I2C interface to connect an oled display.
I use 4 SCT013-030. The SCT013-030 is a non invasive current sensor that converts a maximum of 30A in a signal of 1V.
We are going to measure AC current so the output signal goes from -1V to +1V. But our ADC works in a range os 0 to 3.3V so we have to use a circuit to change the voltage. We are going to use an OP amplifier. The LM324 has 4 inside.
I use only one ADC from the board, I need an analog multiplixer to receive the four analog inputs from the 4 sensors.
I have design a shield to connect to the Azure Sphere MT3620.
I have divided the code in two. One real time application runs in one M4 core to read the analogs signals, and send them to the M7 Core that it is running an application that receive the information, update the oled display and send them to the Cloud Iot platform using a secure channel.
In the M4 core I read the analog signals. The adc0 GPIO41 is the information from the ambient light sensor. In ADC1, GPIO 42 is the output of the analog mulplixer, and GPIO 16 and 17 are used to select the 4 channels of the analog multiplixer.
In order to read the current we have to read the analog signal during 14 cycles of the signal or more. I use 25 cycles.
In the app_manifest.json it is important to add the id from the M7 application to the "AllowedApplicationConnections" field and all the GPIO.
The M7 core runs a code to receive the information from the M4 core, update the oled display and send the information to the Google IoT Core using a secure channel.
First I used Azure IoT Central application to receive the data, but the trial expire in a month so I have to change to another cloud service. This is the tutorial I used
It is really easy to do it following the steps
I move to Google cloud and there the secure channel is based in a Json Web Token(JWT) authentification. Cloud IoT Core uses public key authentication, and supports the RSA and Elliptic Curve algorithms. Here it is a good tutorial to connect an esp32, I adapt it for the Mt3620 http://nilhcem.com/iot/cloud-iot-core-with-the-esp32-and-arduino
We can use MQTT or HTTP, I use HTTP. To send telemetry events to the Cloud using the HTTP bridge, you have to send a POST request containing base64 encoded data to a given URL. The request must contain an authorization
header with a valid JWT generated using your device’s private key.
Following the tutorial I deploy InfluxDB and Grafana in order to store the data.
The power is the current multiply by the voltage in Spain 230V. Grafana does the conversion. Here is a dashboard example
Comments