Air Purifier
•
IA Kit Doc
Sensors
Screen
Internal Memory
Appliance Control
Project
Sensors
Screen
Internal Memory
Appliance Control
Project
Air Purifier
Guest
// Fill in the place with /* */ /* include Incipe library*/ #define SSID "SSID" #define PASSWORD "PASSWORD" #define HOST_NAME /* join the IP of host */ #define HOST_PORT (8090) const int controlPin = 4; //used to control on off void setup(void) { Serial.begin(9600); incipe.wifi.setOprToStationSoftAP(); if (incipe.wifi.joinAP(SSID, PASSWORD))//join wifi { Serial.print("Join AP success"); Serial.print("IP: "); Serial.println(incipe.wifi.getLocalIP().c_str()); } else { Serial.print("Join AP failure"); } incipe.wifi.enableMUX(); pinMode(controlPin, OUTPUT); //used to control on off } void loop(void) { /* create an array to store the message from host */ static uint8_t mux_id = 0; if (incipe.wifi.createTCP(mux_id, HOST_NAME, HOST_PORT)) //join the TCP created by host { Serial.print("create tcp ok"); } else { Serial.print("create tcp err"); } uint32_t command = incipe.wifi.recv(mux_id, receive, sizeof(receive), 10000); if (command > 0) { for(uint32_t i = 0; i < command; i++) { if (receive[i] == 1) // when the host send 1 { digitalWrite(controlPin, HIGH); // turn on the air purifier } else if (receive[i] == 2) // when the host send 2 { digitalWrite(controlPin, LOW); // turn off the air purifier } } } /* send the message "Finish" back to host */ incipe.wifi.releaseTCP(mux_id); delay(1000); }
Host
// Fill in the place with /* */ /* include Incipe library*/ #define SSID "CSWNG" #define PASSWORD "ABC12345" void setup(void) { Serial.begin(9600); incipe.init(); if (incipe.wifi.joinAP(SSID, PASSWORD))//join wifi { Serial.print("Join AP success"); Serial.print("IP: "); Serial.println(incipe.wifi.getLocalIP().c_str()); } else { Serial.print("Join AP failure"); } incipe.wifi.enableMUX(); if (incipe.wifi.startTCPServer(8090))//create a channel for guest { Serial.print("start tcp server ok"); } else { Serial.print("start tcp server err"); } incipe.wifi.setTCPServerTimeout(10); } void loop(void) { /* get air quality from sensor*/ /* classify "poor", "moderate" and "good" using air quality sensor data*/ /* print "poor", "moderate" or "good" on IA Kit screen*/ /* repeat the above steps for CO gas sensor */ /* create an array to store the message from guest */ uint8_t mux_id;//create a value to record the guest number if(/* air quality is poor OR CO gas level is high OR the button indicate manuelly on is pressed */) { char *command = "1"; incipe.wifi.send(mux_id, (const uint8_t*)command, strlen(command)); //send 1 to air purifier (indicate on) } else if (/* air quality is good OR CO gas level is low OR the button indicate manuelly off is pressed */)) { char *command = "2"; incipe.wifi.send(mux_id, (const uint8_t*)command, strlen(command)); //send 2 to air purifier (indicate off) } /* reveice the message from guest */ /* print the message */ incipe.screenWriteValue("xxx.val", -1); }
© 2025 INCIPE Academy Limited





