This is the 3rd blog post for the "IoT on Wheels Design Challenge"
Temperature Alert Logic:
- Temperature Unit: This can take only two values, 0 for Celsius and 1 for Fahrenheit. Default value will be 1 (Fahrenheit).
- Temperature Threshold: If the sensed temperature is above this value, alert mechanism will be activated. Default value will be set to 85 F.
- Desired Telemetry Interval:This sets the how frequently the data is transmitted to cloud. This will be set as follows:
- 5 seconds: During setup of the device. That is when a new device is being setup to connect to cloud through the mobile app.
- 15 minutes: This will be the normal frequency at which the temperature data is transmitted to cloud. This long duration is considered to save data transmission fees as the device will have to connect to cloud through a cellular connection.
- 5 seconds for 15 minutes: When an alert occurs the temperature data will be transmitted to cloud every 5 seconds. Also an email and / or text message will be sent to the contact information stored. But this will occur only for 15 minutes or till some action is taken. For now I have no way of knowing that the driver has opened the windows or started fan / air-conditioning either manually or remotely. This logic may change once the system is adapted.
- Mobile number and / or Email address of Contact Person: The alert details will be sent to this contact.
- Wi-Fi Connection Details: SSID and password to connect through Wi-Fi. This Wi-Fi connection will be used to connect to the mobile app and / or transmit data to cloud when it is available. Currently the password stored will be in clear text but it will be encrypted in future adaptations.
- Azure IoT Hub Connection String: This is got from Azure when the device is registered with the IoT Hub. This also will be in clear text for now.
Coding for Generating a Temperature Alert:
Sensor Board Readings:
- The sensors of the Sensor Board are read in the function FillTheModelInstance(void) in the file AzureClient_mqtt_DM_TM.c.
- Besides Temperature & Humidity sensors there are also Accelerator and Gyroscope. All values are read in this function only.
- The temperature is read in Celsius. So if the Temperature Unit is set to Fahrenheit then the read value is converted to Fahrenheit as shown in the picture below.
- If the Temperature is above the TemperatureThreshold then the TemperatureAlert is set to True otherwise it is set to False. The value of this TemperatureAlert will be used by Azure to activate Alert functionality.
Send Sensor Data to Cloud (Azure):
- The temperature data is transmitted to Azure by the function SendSNSData_Original(void) in the file AzureClient_mqtt_DM_TM.c.
- The following picture shows the data being serialized and transmitted.
- The ellipses in the picture contains the code to actually transmit the data and error processing.
- A word about naming of the function. The actual function is SendSNSData(void). But to manage the different data transmit intervals, this name is used to manage that time interval. When the time is up for sending the data the function SendSNSData_Original(void) will be called. This interval management code is still being finalized.