Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Change Wifi Config On Webpage

Hi, I'm a newbie with Mongoose OS, I'm looking for a guide for change STA Wifi config on AP mode. Is there any solution for this issues? Thanks

Comments

  • holla2040holla2040 Montrose, CO

    I was just about to ask the same question. Is this feature in the backlog?

  • rojerrojer Dublin, Ireland

    the easiest way is to use mos CLI while connected to the AP:

    mos --port ws://192.168.4.1/rpc config-set wifi.sta.enable=true wifi.sta.ssid=SSID wifi.sta.pass=PASS
    
  • lee_trieulee_trieu Viet Nam
    @rojer thank for your post. But, in my case i wanna change wifi config by using webpage on AP mode. Sush as, user will access AP mode, enter ip 192.168.4.1, and type SSID and Password on webpage, and click set for apply wifi config.
  • SergeySergey Dublin, Ireland
    edited April 20

    all RPC calls can use RESTful transport. that means that the RPC call Rojer has shown, could be easily triggered via the web page, or curl tool.

    To call an RPC server via the web page, do an AJAX call to this URL:

    http://IP/rpc/RPC_METHOD_NAME, and POST the required parameters as JSON string.

    Here is a curl command that sets a wifi config:

    curl -d '{config: {wifi: {sta: {enable: true, ssid: "NET", pass: "PASS"}}}}' http://IP/rpc/Config.Set
    
  • lee_trieulee_trieu Viet Nam

    Hi @Sergey Thank you so much! I can get SSID and Password from URL via REST API now, can you please let me know how can i config SSID and Password for STA mode with js ?
    Below is my code for handle SSID and Password from REST API:

    RPC.addHandler('wifi_config', function(args) {
      print("SSID: " + args.ssid);
      print("PASSWORD: " + args.password);
      return {ssid: args.ssid,password: args.password};
      // I don't know how to config SSID and Password for STA mode ? 
    });
  • SergeySergey Dublin, Ireland

    @lee_trieu the answer is already given for you. Please try to understand it.

  • lee_trieulee_trieu Viet Nam

    Hi @Sergey ,

    I followed for suggestion. I'm trying to use Postman to send POST request like picture below:
    POST Wifi Config From Postman

    But, seem the config of wifi not be changed. Can you please make me clearly understand it. Thank you so much !

  • SergeySergey Dublin, Ireland

    use curl, it's easier to reproduce and tell what to do.
    show your curl command that does not work.

  • lee_trieulee_trieu Viet Nam
    edited April 19

    Hi @Sergey
    I also tried to use CURL command, it does not work too.
    Below picture show my CURL command and response from ESP8266. I'm using Raspberry Pi to call CURL, nothing response when i call command. Seem ESP8266 received my command, but not thing change on my wifi config.
    My CURL command: curl -d '{wifi: {sta: {enable: true, ssid: "NET", pass: "PASS"}}}' http://192.168.1.9/rpc/Config.Set
    enter image description here

  • SergeySergey Dublin, Ireland

    Getting wifi config:

    $ curl http://192.168.1.36/rpc/Config.Get
    {"http":{"enable":true,"listen_addr":"80","ssl_cert":"","ssl_key":"","ssl_ca_cert":"","upload_acl":"*","hidden_files":"","auth_domain":"","auth_file":""},"aws":{"shadow":{"thing_name":""}},"rpc":{"enable":true,"max_frame_size":4096,"max_queue_size":25,"mqtt":{"enable":true,"is_trusted":true},"uart":{"uart_no":0,"baud_rate":115200,"fc_enable":false,"wait_for_start_frame":true},"ws":{"enable":true,"server_address":"","reconnect_timeout_min":10,"reconnect_timeout_max":60,"ssl_server_name":"","ssl_ca_file":"","ssl_client_cert_file":""}},"dns_sd":{"enable":true,"host_name":"digipigi_ze1c52","txt":"","ttl":120},"i2c":{"enable":true,"sda_gpio":12,"scl_gpio":14,"debug":false},"mqtt":{"enable":false,"server":"broker.hivemq.com:1883","client_id":"","user":"","pass":"","reconnect_timeout_min":2,"reconnect_timeout_max":60,"ssl_cert":"","ssl_key":"","ssl_ca_cert":"","ssl_cipher_suites":"","ssl_psk_identity":"","ssl_psk_key":"","clean_session":true,"keep_alive":60,"will_topic":"","will_message":""},"sntp":{"enable":true,"server":"pool.ntp.org","retry_min":1,"retry_max":30,"update_interval":7200},"update":{"url":"","interval":0,"timeout":300,"commit_timeout":0,"ssl_ca_file":"ca.pem","ssl_client_cert_file":"","ssl_server_name":"","enable_post":true},"wifi":{"sta":{"enable":true,"ssid":"Cesanta","pass":"EmbeddedCommunication","ip":"","netmask":"","gw":"","nameserver":"","dhcp_hostname":""},"ap":{"enable":false,"ssid":"Mongoose_??????","pass":"Mongoose","hidden":false,"channel":6,"max_connections":10,"ip":"192.168.4.1","netmask":"255.255.255.0","gw":"192.168.4.1","dhcp_start":"192.168.4.2","dhcp_end":"192.168.4.100","keep_enabled":true,"trigger_on_gpio":-1}},"device":{"id":"esp8266_067082","password":""},"debug":{"udp_log_addr":"","mbedtls_level":0,"level":3,"stdout_uart":0,"stderr_uart":0,"factory_reset_gpio":-1,"mg_mgr_hexdump_file":""},"sys":{"atca":{"enable":false,"i2c_addr":96,"ecdh_slots_mask":12},"wdt_timeout":30},"conf_acl":"*"}
    
  • lee_trieulee_trieu Viet Nam

    Hi @Sergey ,
    I tried to use Cifig.Get command and it also response like your post.
    enter image description here
    I also tried to update Mongoose OS to latest version, then i try to send Config.Set, seem ESP8266 received SSID but it still not change my wifi seting.
    enter image description here

  • SergeySergey Dublin, Ireland
    edited April 20
    curl -d '{config:{wifi:{ap:{enable: false}, sta:{enable:true, ssid: "XXX", pass: "YYY"}}}}' IPADDR/rpc/Config.Set
    

    Don't forget to save the config afterwards.

  • lee_trieulee_trieu Viet Nam

    Hi @Sergey ,
    Thank you so much, i will try your command again.
    Can you please guide me how to save the config after change it ? I didn't found any command for save config.
    enter image description here

  • SergeySergey Dublin, Ireland

    There is an RPC service to save config. Go to the RPC browser in the UI, it's there.

  • lee_trieulee_trieu Viet Nam

    @Sergey said:
    There is an RPC service to save config. Go to the RPC browser in the UI, it's there.

    Hi @Sergey ,
    I really appreciate it! Thank you so much.
    It work well for me !

Sign In or Register to comment.