The snippet application folder includes a sample application showing how to use the I2C protocol to read the temperature sensor’s value. Basic API calls may then be used to read the room temperature.
The I/Os may be configured in the platform files. The platform.c file includes all the pin-out mappings and their respective configurations. When configuring the I2C pins, it is necessary to verify:
- the I2C port to which the temperature sensor is connected;
- the SDA and SCL pins;
- the driver to be used.
Another application code snippet integrates a 128px x 128px display into the design. By combining the two applications, it is possible to read the temperature of the room over the I2C interface and to show the value on the display.
To write this application, the flow is:
- Initialize WICED;
- Initialize the I2C device;
- Initialize the display;
- Read the I2C value from the temperature sensor;
- Via SPI or I2C, show the value on the mini display.
Thus far, the system is simply implementing basic, dumb thermometer functions. The next step is to add intelligence: for instance, to compare the desired temperature to the present temperature and, if the room temperature is lower than the desired temperature, to switch on the heating via the relay.
After this, the developer will want to enable the thermometer to connect to a Wi-Fi network in range. Initializing the network stack offers the user a choice of operating modes:
- STA interface – station-based, in which the thermostat is a client;
- Soft AP – in which the thermostat hosts a webserver;
- SoftAP and STA – known as APSTA mode, here the thermostat can operate in both server and client modes.