void PC_pwrSwitchShort() { Serial.println("do pwrSwitchShort"); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "cmdRes"); mqttclient.publish(tmp_topic_pub, "PC_POWER", mqtt_outRetain); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-POWER"); mqttclient.publish(tmp_topic_pub, "ON", mqtt_outRetain); digitalWrite(PIN_OUT_POWERSW, OUT_POWERSW_ONSTATE); pwrSwitchStateOn=true; pwrSwitchOnAt=millis(); pwrSwitchOffAfter=300; } void PC_pwrSwitchHold() { Serial.println("do pwrSwitchHold"); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "cmdRes"); mqttclient.publish(tmp_topic_pub, "PC_POWER_H", mqtt_outRetain); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-POWER-HOLD"); mqttclient.publish(tmp_topic_pub, "ON", mqtt_outRetain); digitalWrite(PIN_OUT_POWERSW, OUT_POWERSW_ONSTATE); pwrSwitchStateOn=true; pwrSwitchOnAt=millis(); pwrSwitchOffAfter=5000; } void PC_pwrSwitchOffAfterTimeout() { if(pwrSwitchStateOn) { if( (millis() - pwrSwitchOnAt) > pwrSwitchOffAfter ) { digitalWrite(PIN_OUT_POWERSW, !OUT_POWERSW_ONSTATE); pwrSwitchStateOn=false; pwrSwitchOffAfter=0; sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-POWER"); mqttclient.publish(tmp_topic_pub, "OFF", mqtt_outRetain); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-POWER-HOLD"); mqttclient.publish(tmp_topic_pub, "OFF", mqtt_outRetain); } } } void PC_resSwitch() { Serial.println("do resSwitch"); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "cmdRes"); mqttclient.publish(tmp_topic_pub, "PC_RESET", mqtt_outRetain); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-RESET"); mqttclient.publish(tmp_topic_pub, "ON", mqtt_outRetain); digitalWrite(PIN_OUT_RESETSW, OUT_RESETSW_ONSTATE); resSwitchStateOn=true; resSwitchOnAt=millis(); resSwitchOffAfter=500; } void PC_resSwitchOffAfterTimeout() { if(resSwitchStateOn) { if( (millis() - resSwitchOnAt) > resSwitchOffAfter ) { digitalWrite(PIN_OUT_RESETSW, !OUT_RESETSW_ONSTATE); sprintf(tmp_topic_pub, "%s/%s", mqtt_topic_out, "PC-RESET"); mqttclient.publish(tmp_topic_pub, "OFF", mqtt_outRetain); resSwitchStateOn=false; resSwitchOffAfter=0; } } } void PC_toOn() { if(PCstate != 1) PC_pwrSwitchShort(); } void PC_toSleep() { if(PCstate == 1) PC_pwrSwitchShort(); }