pre-eth-dbg

This commit is contained in:
Siwat Sirichai 2023-12-31 15:53:39 +07:00
parent e8804864b8
commit 443a02c319
7 changed files with 240 additions and 79 deletions

View file

@ -17,6 +17,7 @@ size_t getInfraredCode(uint8_t mode, uint8_t fan_speed, uint8_t temperature, con
*codePtr = &(irCode[mode][fan_speed][temperature][0]);
return sizeof(irCode[mode][fan_speed][temperature]) / sizeof(uint16_t);
}
AirConditioner ac = {
.max_temperature = 30,
.min_temperature = 16,
@ -26,6 +27,7 @@ AirConditioner ac = {
.fan_speed_names = fan_speed_names,
.getInfraredCode = &getInfraredCode
};
ClimateCard climateCard = ClimateCard(14, ac);
void input_change_callback(uint8_t pin, uint8_t value) {
@ -35,76 +37,55 @@ void input_change_callback(uint8_t pin, uint8_t value) {
Serial.println(value);
}
void setNetworkConfig() {
NetworkConfig config = {
.ip = {192, 168, 0, 11},
.gateway = {192, 168, 0, 1},
.subnet = {255, 255, 255, 0},
.dns1 = {192, 168, 0, 1},
.dns2 = {192, 168, 0, 1},
.useStaticIp = true,
.useWifi = false,
.wifiUseAuth = false,
};
strcpy(config.ssid, "ssid");
strcpy(config.password, "password");
strcpy(config.hostname, "espmega");
Serial.println("Setting network config");
espmega.iot->setNetworkConfig(config);
espmega.iot->saveNetworkConfig();
}
void setMqttConfig() {
MqttConfig config = {
.mqtt_port = 1883,
.mqtt_useauth = false
};
strcpy(config.mqtt_server, "192.168.0.26");
strcpy(config.base_topic, "/espmegaoop");
espmega.iot->setMqttConfig(config);
espmega.iot->saveMqttConfig();
}
void setup() {
// Set each class's log level
esp_log_level_set("ESPMegaPRO", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalOutputCard", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalOutputIoT", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalInputCard", ESP_LOG_VERBOSE);
esp_log_level_set("DigitalInputIoT", ESP_LOG_VERBOSE);
esp_log_level_set("AnalogCard", ESP_LOG_VERBOSE);
esp_log_level_set("AnalogIoT", ESP_LOG_VERBOSE);
esp_log_level_set("ClimateCard", ESP_LOG_VERBOSE);
esp_log_level_set("ClimateIoT", ESP_LOG_VERBOSE);
esp_log_level_set("InternalDisplay", ESP_LOG_VERBOSE);
esp_log_level_set("InternalDisplayIoT", ESP_LOG_VERBOSE);
espmega.begin();
espmega.enableIotModule();
ETH.begin();
espmega.iot->bindEthernetInterface(&ETH);
// NetworkConfig config = {
// .ip = {192, 168, 0, 11},
// .gateway = {192, 168, 0, 1},
// .subnet = {255, 255, 255, 0},
// .dns1 = {192, 168, 0, 1},
// .dns2 = {192, 168, 0, 1},
// .useStaticIp = true,
// .useWifi = false,
// .wifiUseAuth = false,
// };
// strcpy(config.ssid, "ssid");
// strcpy(config.password, "password");
// strcpy(config.hostname, "espmega");
// Serial.println("Setting network config");
// espmega.iot->setNetworkConfig(config);
// espmega.iot->saveNetworkConfig();
espmega.iot->loadNetworkConfig();
Serial.println("Connecting to network");
espmega.iot->connectNetwork();
Serial.println("Begin MQTT Modules");
// MqttConfig mqtt_config = {
// .mqtt_port = 1883,
// .mqtt_useauth = false
// };
// Serial.println("Setting MQTT Server");
// strcpy(mqtt_config.mqtt_server, "192.168.0.26");
// strcpy(mqtt_config.base_topic, "/espmegaoop");
// Serial.println("Loading MQTT Config Struct to IoT Module");
// espmega.iot->setMqttConfig(mqtt_config);
// espmega.iot->saveMqttConfig();
espmega.iot->loadMqttConfig();
Serial.println("Connecting to MQTT");
espmega.iot->connectToMqtt();
Serial.println("Registering Output Card");
espmega.iot->registerCard(0);
Serial.println("Registering Input Card");
espmega.iot->registerCard(1);
Serial.println("Registering Input Change Callback");
espmega.inputs.registerCallback(input_change_callback);
Serial.println("Installing Climate Card");
espmega.installCard(2, &climateCard);
climateCard.bindFRAM(&espmega.fram, 301);
climateCard.loadStateFromFRAM();
climateCard.setFRAMAutoSave(true);
Serial.println("Enabling Internal Display");
espmega.enableInternalDisplay(&Serial);
espmega.display->bindClimateCard(&climateCard);
Serial.println("Initialization Routine Complete");
Serial.write(0xFF);
Serial.write(0xFF);
Serial.write(0xFF);
Serial.println(sizeof(MqttConfig));
Serial.println(sizeof(NetworkConfig));
}
@ -112,13 +93,14 @@ void setup() {
// Every 20 seconds, dump FRAM 0-500 to serial
void loop() {
espmega.loop();
// static uint32_t last_fram_dump = 0;
// if (millis() - last_fram_dump >= 20000) {
// last_fram_dump = millis();
// Serial.println("Dumping FRAM");
// espmega.dumpFRAMtoSerial(0, 500);
// Serial.println("Dumping FRAM ASCII");
// espmega.dumpFRAMtoSerialASCII(0, 500);
// }
#ifdef FRAM_DEBUG
static uint32_t last_fram_dump = 0;
if (millis() - last_fram_dump >= 20000) {
last_fram_dump = millis();
Serial.println("Dumping FRAM");
espmega.dumpFRAMtoSerial(0, 500);
Serial.println("Dumping FRAM ASCII");
espmega.dumpFRAMtoSerialASCII(0, 500);
}
#endif
}