Replies: 5 comments 1 reply
-
Hi Colin this is were i have got to its a running version but still has a few things to polish wifi manager can be called with diferant options i need to explore these some more as in the event of a router going down i am trying to get the code to cycle between logging in on saved details and giving a AP to enter new details if it cant log in . in the compile it needs to be set up to save as flash size 4m 1m spiffs easy then to erase at compile time to test as a clean install .. #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #ifdef ESP32 #include <ArduinoJson.h> //https://github.com/bblanchon/ArduinoJson // Update these to match your inverter/network. // The device name is used as the MQTT base topic. If you need more than one Sofar2mqtt on your network, give them unique names. //define your default values here, if there are different values in config.json, they are overwritten. //default custom static IP //#define MQTT_SERVER "" // these not used #if (! defined INVERTER_ME3000) && ! defined INVERTER_HYBRID #include <Arduino.h> #define SOFAR_SLAVE_ID 0x01 #ifdef INVERTER_ME3000 #define RS485_TRIES 8 // x 50mS to wait for RS485 input chars. // MQTT parameters // SoftwareSerial is used to create a second serial port, which will be deidcated to RS485. // Sofar run states #ifdef INVERTER_ME3000 #define HUMAN_CHARGING "Charging" #elif defined INVERTER_HYBRID // State names are a bit strange - makes sense to also match to these? #define HUMAN_CHARGING "Normal" #define MAX_FRAME_SIZE 64 unsigned int INVERTER_RUNNINGSTATE; // Battery Save mode is a hybrid mode where the battery will charge from excess solar but not discharge. // SoFar ME3000 Information Registers #define SOFAR_FN_STANDBY 0x0100 struct mqtt_status_register static struct mqtt_status_register mqtt_status_reads[] = // This is the return object for the sendModbus() function. Since we are a modbus master, we // These timers are used in the main loop. // Wemos OLED Shield set up. 64x48, pins D1 and D2 /**
// Update the OLED. Use "NULL" for no change or "" for an empty line. void updateOLED(String line1, String line2, String line3, String line4)
} //flag for saving data //callback notifying us of the need to save config // end new code // Connect to WiFi
***/ /* int addStateInfo(String &state, uint16_t reg, String human)
} void sendData()
} // This function is executed when an MQTT message arrives on a topic that we are subscribed to.
bool messageBool = ((messageTemp != "false") && (messageTemp != "battery_save"));
} void batterySave()
} // This function reconnects the ESP8266 to the MQTT broker
} /**
int sendModbus(uint8_t frame[], byte frameSize, modbusResponse *resp)
} // Listen for a response.
} int readSingleReg(uint8_t id, uint16_t reg, modbusResponse *rs)
} int sendPassiveCmd(uint8_t id, uint16_t cmd, uint16_t param, String pubTopic)
} void sendMqtt(char* topic, String msg_str)
} void heartbeat()
} void updateRunstate()
#ifdef INVERTER_ME3000
} unsigned int batteryWatts()
} void setup()
delay(100); //new code below wifi man //clean FS, for testing //read configuration from FS json if (SPIFFS.begin()) {
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6
} else { // The extra parameters to be configured (can be either global or just in the setup) //WiFiManager //set config save notify callback //set static ip wifiManager.setSTAStaticIPConfig(_ip, _gw, _sn); //add all your parameters here //set minimu quality of signal so it ignores AP's under that quality display.clearDisplay(); // not sure if i need this again //sets timeout until configuration portal gets turned off //fetches ssid and pass and tries to connect if (!wifiManager.autoConnect("SofarAP", "password")) { display.clearDisplay(); int delay1 = 5; // thought be nice for a count down tell us
// delay(5000); // should never get here think we can change wifi //if you get here you have connected to the WiFi //read updated parameters
#if defined(ARDUINOJSON_VERSION_MAJOR) && ARDUINOJSON_VERSION_MAJOR >= 6 } // added bit below just to confirm it got the details take out when polishing // new code above
// mqtt.setServer(MQTT_SERVER, MQTT_PORT); // origonal line
} void loop()
//Serial.println("loop time "); // just seeing how fast we are looping //calcCRC and checkCRC are based on... void calcCRC(uint8_t frame[], byte frameSize)
} bool checkCRC(uint8_t frame[], byte frameSize)
} /*****
Subscribe your MQTT client to: Sofar2mqtt/state Which provides: running_state With the inverter in Passive Mode, send MQTT messages to: Sofar2mqtt/set/standby - send value "true" Each of the above will return a response on: The result code will be 0 for success, 1 means "Invalid Work Mode" ( which possibly means The status bits in the upper byte indicate the following: For example, a publish to Sofar2mqtt/set/charge will result in one on Sofar2mqtt/response/charge. battery_save is a hybrid auto mode that will charge from excess solar but not discharge. There will also be messages published to Sofar2mqtt/response/ when things happen (c)Colin McGerty 2021 [email protected] |
Beta Was this translation helpful? Give feedback.
-
I've been wondering about doing this, so really glad to see you guys are working on it, thanks very much. Would it be possible to also add fields for the MQTT server IP, port, username, password and device name to this so all variables can be configured when setting up WiFi? |
Beta Was this translation helpful? Give feedback.
-
This does this all the things you need to config. For operation is available. Even the device name you can change
I uploaded a working copy of my ino file last night. Not sure if Colin has put it into the correct directory as yet But. If not I am sure he will soon
I am not to well versed with how to do this
Regards. Bill
On 1 Dec 2022, at 14:17, Martin Saunders ***@***.***> wrote:
I've been wondering about doing this, so really glad to see you guys are working on it, thanks very much. Would it be possible to also add fields for the MQTT server IP, port, username, password and device name to this so all variables can be configured when setting up WiFi?
—
Reply to this email directly, view it on GitHub<#43 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ALRW66E7SUPQHFVTVXRQPKDWLCXPLANCNFSM6AAAAAASF2SQQE>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Hi Colin if you can deleat the code I pasted as it is incompleat. I have managed to upload a zip file this is the code that I am using at present and all seems to work ok. Regards bill |
Beta Was this translation helpful? Give feedback.
-
@Ernest-burgess
Starting a separate thread on WiFi Manager as I am keen to include the feature if you would like to share it with folks.
You can either fork the project to your GitHub and submit a pull request or just paste your .ino file below (remove your passwords) and I'll manually merge it for testing at home.
Thanks for your efforts on this.
Colin
Beta Was this translation helpful? Give feedback.
All reactions