logo elektroda
logo elektroda
X
logo elektroda

How to configure WiFi on Zamel switches via ESP8266?

madiz08 2103 18
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18327234
    madiz08
    Level 14  
    I recently ordered two electrical switch modules from Zamel for controlling lights and roller shutters via WiFi from my phone:
    How to configure WiFi on Zamel switches via ESP8266? .
    By the way, I found out that this box is controlled by an ESP8266. I was wondering how it could be controlled by my Wifi if the device doesn't know my WiFi password, and supposedly everything is configured wirelessly.
    Turns out they did it in a very interesting way:
    1. after pressing the only button for a minimum of 5 seconds, the device enters configuration mode
    2. after entering this mode, in the available WiFi networks, I see an open connection with a name (e.g. ZAMEL_ROW-02)
    3. after connecting and typing 192.168.4.1 in the browser, a window pops up with the possibility to type in my WiFi network and password (and a few other things)
    4. after saving these changes and restarting the device, it already connects to my WiFi network and I can control it from my phone.

    The topic interested me, because often when I do some circuitry on my ESP32, there is a need to correct some parameters and remember them. In order not to have to do this every time I upload a program from the Arduino IDE, I sometimes write applications in Visual Studio that communicate via the UART with the ESP32. However, each time I have to approach the computer and make a wired connection.

    Could you please guide me to some sites with this kind of subject matter where I can learn about something like this. I am talking about setting up a WiFi network on the ESP32, how is this possible?
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • Helpful post
    #2 18327272
    maly_13
    Level 20  
    supla search there is a forum that has been quite busy lately
  • Helpful post
    #3 18327293
    khoam
    Level 42  
    madiz08 wrote:
    Could you please guide me to some sites with this kind of topic, where I can learn about something like this. I am talking about setting up a WiFi network on an ESP32, how is this possible?
    .
    The latest version WiFiManager also supports ESP32. In addition there is IotWebConf . Both libraries use the Arduino HAL for ESP32.
  • #4 18327444
    madiz08
    Level 14  
    Well actually :) Even so you have to enter 192.168.4.1. Great stuff, for now I have an example with LED control (classic ON/OFF), I need to refresh my HTML a bit. I've also seen that there are examples with ready-made scripts that set the WiFi password and login.
  • ADVERTISEMENT
  • Helpful post
    #6 18330558
    pabl0
    Level 10  
    madiz08 wrote:
    .
    Could you please guide me to some sites with this kind of subject matter where I can learn about something like this. I am talking about setting up a WiFi network on an ESP32, how is this possible?


    This is exactly how ESP Easy behaves.
  • #7 18346880
    madiz08
    Level 14  
    I would still just need if anyone knows how I can put what I type in the Textbox into a string type variable on the arduino. I have code like this:
    Code: C / C++
    Log in, to see the code
    .
    and this is what the 192.168.4.1 page looks like
    How to configure WiFi on Zamel switches via ESP8266? .
    If I understand correctly the name of this textbox is textbox5:

    How to configure WiFi on Zamel switches via ESP8266? .
    How to configure WiFi on Zamel switches via ESP8266? .
    and now how can I send text from a textbox instead of what I have highlighted in red?
    I would like to use several textboxes and send texts from all of them, something like:
    Code: C / C++
    Log in, to see the code
    , where later I would already split this text into individual strings in the arduino.

    Added after 26 [minutes]: .

    When I try to use some java scripts it gives compilation errors of course

    Added after 5 [hours] 41 [minutes]:

    Gentlemen, and maybe you could help me with the following code:
    Code: C / C++
    Log in, to see the code
    .

    based on :
    https://randomnerdtutorials.com/esp32-esp8266-input-data-html-form/
    The above code allows one of the three textboxes to be displayed on the serial monitor, but if I want one button to display the data from the three fields, any modification I make is either an error or gives nothing
  • ADVERTISEMENT
  • Helpful post
    #8 18348166
    ex-or
    Level 28  
    You need to put all the input tags (three of type text and one submit) in one form. See for yourself an example: https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_form_submit
    Of course, you also need to modify the ify decoding the response because at the moment the program only expects one parameter in the response and receives three.
  • #9 18348796
    madiz08
    Level 14  
    Actually works, thanks :) .
    Code: C / C++
    Log in, to see the code
  • #10 18351349
    madiz08
    Level 14  
    In the example below, I have already managed to create a transition into configuration mode, like an access point, where I can enter a name, wifi password and other parameters. If I enter them, the ESP32 resets itself and enters the operating mode where it already connects to my wifi network and additionally the PLC:
    Code: C / C++
    Log in, to see the code
    .

    The next step I would like to do is to be able to send commands from a browser or application, where for example sending 192.168.0.85/H will cause an LED to light up for now. Previously when I did things like this I used :
    Code: C / C++
    Log in, to see the code
    .

    However, when adding something like this to my current code it causes compilation errors telling me that :

    How to configure WiFi on Zamel switches via ESP8266? .

    For the AsyncWebServer library, how can I write a read of what came from the client, and then against that perform the given actions?
  • #11 18352260
    madiz08
    Level 14  
    Perhaps I should ask the question differently:
    The problem is that I would like to use in two different libraries in different cases, and I declare all of them at the beginning.
    1. as after turning on the ESP32 I am in configuration mode and I want to enter parameters from a page put on the wifi network of my ESP32 I use ESPAsyncWebServer.h
    2. as after switching on the ESP32 is in normal operating mode, i.e. it has connected to my wifi based on the parameters previously entered in configuration mode, I would now like the ESPAsyncWebServer.h library to no longer be taken into account and not affect compilation errors WiFiClient client = server.available();. At this point, I would like to use the standard wifi.h library only

    The dependency of whether I am entering configuration mode comes from reading EERROMread(0). If the value of this byte is <10 then I am in normal mode, otherwise in configuration mode

    Is it possible to use one or the other library depending on the condition, or can they somehow be changed for such a need?
  • Helpful post
    #12 18352874
    khoam
    Level 42  
    madiz08 wrote:
    the problem is that I would like to use in two different libraries in different cases, and I declare all of them at the beginning.
    .
    And here's the problem. Since you want to use ESPAsyncWebServer only in configuration mode, you should move all handling of this mode to a separate function with local variable 'server'. Once the configuration is complete and the function exits, the resources allocated for ESPAsyncWebServer will be released automatically.
  • #13 18353477
    madiz08
    Level 14  
    So you mean I should paste this whole library into a separate function? I don't think I quite understand if it's supposed to be in a model:
    Code: C / C++
    Log in, to see the code
    .
  • ADVERTISEMENT
  • #14 18353495
    khoam
    Level 42  
    madiz08 wrote:
    You mean that I should paste this entire library into a separate function?
    .
    Yes, in a separate function together with the variable declarations relating only to ESPAsyncWebServer and the code that operates on those variables.

    You can also put the normal mode call in a separate function - it will be easier to read. On the other hand, leave as global variables only those you will refer to from both modes of operation.

    Added after 28 [minutes]: .

    One more thing - to make the execution of configuration mode completely independent of what happens in loop() add your own loop inside function_mode_configuration():
    Code: C / C++
    Log in, to see the code
    This way, the operation of the main loop() will be paused while the configuration mode is handled, i.e. the specified condition in while() is met. After exiting this function, the program will return to the loop().
  • #15 18353656
    madiz08
    Level 14  
    Ok, thank you. I won't be able to sit down to this again today. I'll try to get to it solidly tomorrow morning.
  • #16 18354128
    madiz08
    Level 14  
    Initially, I depleted the code to enter only the configuration mode:

    Code: C / C++
    Log in, to see the code
    .

    and as such I tried to modify it so that the whole thing was in the configuration function.
    At first I tried to move the HTML page there, without success, but after commenting out the libraries and what's in the config function the compiler didn't throw me any errors for the HTML build, also I guess it could stay that way?

    How to issue function_config mode() only executes once, so the do-while loop is empty

    I finally got around to transferring the libraries. At first I simply tried it this way:
    Code: C / C++
    Log in, to see the code
    .

    .
    How to configure WiFi on Zamel switches via ESP8266?
    .

    When I paste the entire contents of a library instead of the library in question, every now and then compilation errors occur for the absence of various other libraries

    Could you guide me how to declare the local variable 'server', maybe that is the problem
  • #17 18354255
    khoam
    Level 42  
    The #include header files cannot be inside a function. They must be at the beginning of the file, which is how you had them before and you don't need to change that.

    Loop to ... while (condition_output<1) will keep executing as long as the variable 'condition_output' is less than 1, i.e. over and over again, if you initialise the variable 'condition_output' with a value of 0 and don't change it afterwards - that's not what you meant, is it?
  • #18 18354538
    madiz08
    Level 14  
    Works!!!!!!!!!!!!!!!!!! :) .
    Regarding the looping thing, I'm well aware of the no-networking, I just did it as a test so that I don't leave that mode.
    That is, #include always at the beginning of the code, and I gave AsyncWebServer server(80); in the config function.
    For now, it works like the ZAMEL module:
    1. when I am not in configuration mode (and I need to set the parameters), I press the button for 2 seconds, after which the value >10 is written to the EEPROM(0) and the ESP is reset.
    2) After starting the EEPROM(0) >10, ESP enters the configuration function where the AsyncWebServer server(80) is loaded; and grinds continuously in the do-while
    3. as I enter the appropriate parameters with the browser and click save, all these parameters are written to the EEPROM, including EEPROM(0)<10
    4. after a reset, the ESP32 checks that EEPROM(0)<10 and enters normal_operation mode, loading WiFiServer server(80); from the standard WiFi library, connecting to my local network. I can now connect to the PLC and await information from the browser (although I haven't tested this yet). Everything is done in a do-while, so the main loop loop is not used.
    This loop also checks the status of a button which, if I hold down for 2s, the ESP resets and goes into configuration mode.

    Thanks for your help

    Added after 8 [minutes]:

    I've just switched the LED on and off from the browser. Super thing to know that you can use a particular library as needed :)

Topic summary

The discussion revolves around configuring Zamel electrical switch modules, which utilize the ESP8266 for WiFi control. The configuration process involves entering a setup mode by pressing a button, connecting to an open WiFi network created by the device, and accessing a web interface at 192.168.4.1 to input the user's WiFi credentials. Various responses provide insights into using libraries like WiFiManager and IotWebConf for ESP32, handling input parameters in Arduino code, and managing configuration and operational modes through EEPROM. The conversation also touches on best practices for coding, such as separating configuration and operational logic into distinct functions and utilizing the Preferences class for data storage instead of EEPROM.
Summary generated by the language model.
ADVERTISEMENT