MQTT topic and message description :

Kit have two Capsense button. I used that as two switches.

Capsense 1 --> Topic : cap1 --> Message : TURNON/TURNOFF

Capsense 2 --> Topic : cap2 --> Message : TURNON/TURNOFF

Flow Chart:

 .

Our module code is designed to handle all user operations to control home electronics appliances using our smart home automation system. The system offers four modes of operation:

  • Touch: The Cypress capacitive touch technology senses user touch input and reacts based on the last state of the relay value.
  • Voice Command: Alexa publishes MQTT messages, which our ESP module subscribes to receive. I2C communication is used between the Cypress chip and the ESP8266 to enable voice command operation.
  • IR Remote: Our ESP8266 decodes user input button commands and sends them to the Cypress chip using I2C communication. The Cypress chip reacts based on the input command.
  • Smartphone: The user's smartphone can publish MQTT messages, which our ESP module subscribes to receive. I2C communication is used between the Cypress chip and the ESP8266. Based on the received command, the Cypress chip reacts and handles the relay.

Our module code allows for seamless integration of these four modes, offering users flexibility and convenience in controlling their home electronics appliances.

CypressCode:

1. To import C libraries in your code, you need to include their header files using the #include preprocessor directive. This allows you to use functions and data types from the library in your program.

#include "project.h"
#include "stdlib.h"
#include "cyapicallbacks.h"

2. The code snippet you provided consists of four C function prototypes. These are:

void updateLoad(void);
void loadWrite(uint8,uint8);
void HandleError(void);
void i2cReceive(void);
  • void updateLoad(void): A function that updates the load status of a device.
  • void loadWrite(uint8, uint8): A function that writes a value to a specific load.
  • void HandleError(void): A function that handles errors that may occur during program execution.
  • void i2cReceive(void): A function that receives data via the I2C communication protocol.

These function prototypes define the function name, return type, and parameters (if any) that the function accepts. They are often used as a way to declare functions before they are implemented or used in a program, helping to ensure that the function is properly defined and its usage is correct.

3. The code snippet you provided defines two preprocessor directives using the #define keyword.

#define LightloadNumber 4
#define FanLoadNumber 1
  • #define LightloadNumber 4 defines a preprocessor macro with the name LightloadNumber and a value of 4. This macro can be used in the code to represent the number of light loads that can be controlled by the program.
  • #define FanLoadNumber 1 defines a preprocessor macro with the name FanLoadNumber and a value of 1. This macro can be used in the code to represent the number of fan loads that can be controlled by the program.

These preprocessor directives help to make the code more readable and maintainable by defining values that are used in multiple places throughout the program in one central location. Anytime the program needs to refer to the number of light or fan loads, it can use these macros instead of hardcoding the values, which makes the code more flexible and easier to modify in the future.

4. These lines are declaring and initializing various arrays and variables that will be used in the program for controlling the smart home automation system.

uint8 state_switch[LightloadNumber];       //status of touch switch
uint8 pre_switch[LightloadNumber];         //previous status of touch switch
uint8 state_load[LightloadNumber];         //status of load
uint8 state[LightloadNumber + FanLoadNumber + 1];   //state for communication 
uint8 pre_state[LightloadNumber + FanLoadNumber + 1];   //state for communication 
uint8 state_Fswitch[FanLoadNumber]; //status...
Read more »