This is the 3rd blog post for the "IoT on Wheels Design Challenge"


Temperature Alert Logic:

  1. Related Parameters:

    1. Temperature Unit: This can take only two values, 0 for Celsius and 1 for Fahrenheit. Default value will be 1 (Fahrenheit).
    2. Temperature Threshold: If the sensed temperature is above this value, alert mechanism will be activated. Default value will be set to 85 F.
    3. Desired Telemetry Interval:This sets the how frequently the data is transmitted to cloud. This will be set as follows:
      1. 5 seconds: During setup of the device. That is when a new device is being setup to connect to cloud through the mobile app.
      2. 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.
      3. 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.
    4. Mobile number and / or Email address of Contact Person: The alert details will be sent to this contact.
    5. 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.
    6. 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:

    1. The sensors of the Sensor Board are read in the function FillTheModelInstance(void) in the file AzureClient_mqtt_DM_TM.c.
    2. Besides Temperature & Humidity sensors there are also Accelerator and Gyroscope. All values are read in this function only.
    3. 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.
    4. 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.

Convert Temperature to given Units and set Temperature Alert status

  • Send Sensor Data to Cloud (Azure):

    1. The temperature data is transmitted to Azure by the function SendSNSData_Original(void) in the file AzureClient_mqtt_DM_TM.c.
    2. The following picture shows the data being serialized and transmitted.
    3. The ellipses in the picture contains the code to actually transmit the data and error processing.
    4. 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.


Code showing the data being serialzed and sent to Azure


A Glimpse of the Mobile App being developed (Android version is shown):

Main Menu of the Mobile App (Android version is shown)