Skip to content

ESP8266: static address configuration and dhcp enable/disable added #12721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 13, 2020

Conversation

michalpasztamobica
Copy link
Contributor

Summary of changes

Fixes #12552
I implemented the set_network function, which configures static network address and set_dhcp function.
This function is optional, so no greentea tests are available. I only tested on RAAS, but had no way of really allowing static IP address setting. @star297 , would you please check if this PR works for you?

Impact of changes

New functionalities of ESP8266 are now available.

Migration actions required

None.

Documentation

Doxygen copied from NetworkInterface.

Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[x] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[x] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@SeppoTakalo
@AnttiKauppila
@VeijoPesonen
@star297


@ciarmcom
Copy link
Member

@michalpasztamobica, thank you for your changes.
@AnttiKauppila @VeijoPesonen @SeppoTakalo @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

@michalpasztamobica
Copy link
Contributor Author

I force-pushed astyle fixes.

AnttiKauppila
AnttiKauppila previously approved these changes Mar 31, 2020
@star297
Copy link
Contributor

star297 commented Mar 31, 2020

@michalpasztamobica
It looks okay, but does not work when I cloned your michalpasztamobica:esp8266_set_network Mbed OS version into Studio, compiles but can't set that IP using;

net->set_network((SocketAddress)IP,(SocketAddress)NETMASK,(SocketAddress)GATEWAY);

Perhaps that OS version is a bit old?

Library is at esp8266_set_network but the latest version is 5.9.7.

0xc0170
0xc0170 previously approved these changes Mar 31, 2020
@michalpasztamobica
Copy link
Contributor Author

@star297 , can you try enabling the logs in mbed_app.json:

"mbed-trace.enable": 1,
...
"esp8266.debug": true

With this you should see what's going on over AT commands and you will se if there are any errors.
For me the board did not connect to AP, but I don't have access to the router. Did you configure your router correctly, so the board has the static IP address available without DHCP?
Has this worked outside of mbed-os?
I doubt mbed-os version has anything to do with it...

@star297
Copy link
Contributor

star297 commented Mar 31, 2020

Okay, it does actually work by running 'set_network' resetting IP AFTER connection, so your start up order is wrong

AT+CWMODE_CUR

Has be to be set first before setting IP.

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 31, 2020

CI started

@michalpasztamobica
Copy link
Contributor Author

@0xc0170 , please withhold the merge, I need to comprehend Paul's remark and perhaps adjust the code. I will get down to this as soon as I have a free moment.

@mergify mergify bot dismissed stale reviews from AnttiKauppila and 0xc0170 March 31, 2020 18:57

Pull request has been modified.

@michalpasztamobica
Copy link
Contributor Author

@star297 , thanks a lot for your remark, I just pushed a fix, which hopefully fixes the problem. It calls _init() function before running the configuration AT commands.

@star297
Copy link
Contributor

star297 commented Mar 31, 2020

That should fix it, can I import that to Studio from here?, then I can check.

https://github.com/michalpasztamobica/mbed-os/tree/esp8266_set_network

@michalpasztamobica
Copy link
Contributor Author

Yes, you should be able to import this, just like any other git branch. It sure has the most recent changes.
Although, to be honest, I am not using mbed Studio on a daily basis 😊

@star297
Copy link
Contributor

star297 commented Mar 31, 2020

Sorry Michal that latest import is not working.
Looks like that command is being passed to the ESP before AT initializing, here's the output, you will see all those timeouts that's normally due to sending AT+CIPSTA_CUR command before AT+CWMODE_CUR is set.
I notice repeated commands, AT+CWMODE_DEF=1 and AT+CWMODE_CUR=1.
That AT+CWMODE_DEF=1 needs removing and the AT+CIPSTA_CUR must come after AT+CWMODE_CUR=1.

AT> AT
AT? OK
%n
AT(Timeout)
AT> AT
AT? OK
%n
AT(Timeout)
AT> AT
AT? OK
%n
AT(Timeout)
AT> AT
AT? OK
%n
AT(Timeout)
AT> AT
AT? OK
%n
AT(Timeout)
AT? %n
AT<
AT> AT
AT? OK
%n
AT<
AT= OK

AT> AT+RST
AT? OK
%n
AT= OK

AT? %n
AT? %n
AT< xAT< xxAT< xøxøxøxøxxxxxøxøxøxøAT< xxxxxøøxxAT< àAT< àAT! ready
AT? %n
AT<
AT? %n
AT> AT
AT? OK
%n
AT< AT
AT= OK

AT> ATE0
AT? OK
%n
AT< ATE0
AT= OK
AT> AT+GMR
AT? AT version:%*d.%*d.%*d.%*d%n
AT= AT version:1.7.0.0
AT? OK
%n
AT< (Aug 16 2018 00:57:04)
AT< SDK version:3.0.0(d49923c)
AT< compile time:Aug 23 2018 16:58:12
AT< Bin version(Wroom 02):v1.7.0
AT= OK

AT> AT+GMR
AT? SDK version:%*d.%*d.%*d%n
AT< AT version:1.7.0.0(Aug 16 2018 00:57:04)
AT= SDK version:3.0.0
AT? OK
%n
AT< (d49923c)
AT< compile time:Aug 23 2018 16:58:12
AT< Bin version(Wroom 02):v1.7.0
AT= OK

AT> AT+CWMODE_DEF=1
AT? OK
%n
AT= OK

AT> AT+CWCOUNTRY_DEF=0,"ESP",1,13
AT? OK
%n
AT= OK

AT> AT+CWCOUNTRY_CUR=0,"ESP",1,13
AT? OK
%n
AT= OK

AT> AT+CIPRECVMODE=1
AT? OK
%n
AT= OK

AT> AT+CWMODE_CUR=1
AT? OK
%n
AT= OK

AT> AT+CIPMUX=1
AT? OK
%n
AT= OK

AT> AT+CWJAP_CUR="Molino Metz","36693557"
AT? OK
%n
AT! WIFI
AT? %*12[^"]
%n
AT= CONNECTED

AT? OK
%n
AT! WIFI
AT? %*12[^"]
%n
AT= GOT IP

AT? OK
%n
AT= OK

AT? %n
AT> AT+CIFSR
AT? +CIFSR:STAIP,"%*15[^"]"%n
AT= +CIFSR:STAIP,"192.168.1.46"
AT? OK

This is with the command sent AFTER connecting, no timeouts and the AT+CIPSTA_CUR command changes the IP to 192.168.1.180.

AT> AT
AT? OK
%n
AT<
AT= OK

AT> AT+RST
AT? OK
%n
AT= OK

AT? %n
AT! WIFI
AT? %*12[^"]
%n
AT= DISCONNECT

AT? %n
AT? %n
AT? %n
AT< xAT< xxAT< xøxøxøxøxxxxxøxøxøxøAT< xxxxxøøxxAT< àAT< àAT! ready
AT? %n
AT<
AT? %n
AT> AT
AT? OK
%n
AT< AT
AT= OK

AT> ATE0
AT? OK
%n
AT< ATE0
AT= OK
AT> AT+GMR
AT? AT version:%*d.%*d.%*d.%*d%n
AT= AT version:1.7.0.0
AT? OK
%n
AT< (Aug 16 2018 00:57:04)
AT< SDK version:3.0.0(d49923c)
AT< compile time:Aug 23 2018 16:58:12
AT< Bin version(Wroom 02):v1.7.0
AT= OK

AT> AT+GMR
AT? SDK version:%*d.%*d.%*d%n
AT< AT version:1.7.0.0(Aug 16 2018 00:57:04)
AT= SDK version:3.0.0
AT? OK
%n
AT< (d49923c)
AT< compile time:Aug 23 2018 16:58:12
AT< Bin version(Wroom 02):v1.7.0
AT= OK

AT> AT+CWMODE_DEF=1
AT? OK
%n
AT= OK

AT> AT+CWCOUNTRY_DEF=0,"ESP",1,13
AT? OK
%n
AT= OK

AT> AT+CWCOUNTRY_CUR=0,"ESP",1,13
AT? OK
%n
AT= OK

AT> AT+CIPRECVMODE=1
AT? OK
%n
AT= OK

AT> AT+CWMODE_CUR=1
AT? OK
%n
AT= OK

AT> AT+CIPMUX=1
AT? OK
%n
AT= OK

AT> AT+CWJAP_CUR="Molino Metz","36693557"
AT? OK
%n
AT! WIFI
AT? %*12[^"]
%n
AT= CONNECTED

AT? OK
%n
AT! WIFI
AT? %*12[^"]
%n
AT= GOT IP

AT? OK
%n
AT= OK

AT? %n
AT> AT+CIPSTA_CUR="192.168.1.180","192.168.1.1","255.255.255.0"
AT? OK
%n
AT= OK

AT> AT+CIFSR
AT? +CIFSR:STAIP,"%*15[^"]"%n
AT= +CIFSR:STAIP,"192.168.1.180"
AT? OK

@mbed-ci
Copy link

mbed-ci commented Apr 1, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 1
Build artifacts

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 1, 2020

@michalpasztamobica will wait for confirmation

@michalpasztamobica
Copy link
Contributor Author

@star297 , not sure what code produced that first log you pasted, but what I am seeing is that you somehow sent AT commands before _init() function... You can tell _init() is running when you see these:

AT> ATE0
AT? OK
%n
AT< ATE0
AT= OK

as this is echo_off() function and there's just one place this can possibly come from.
I made sure that the _init() function gets called before we actually send the AT command...

So I wonder how come the CIPSTA_CUR= could happen before ATE0? I think the AT timeouts must be some other commands...
Also - when I ran my code on RAAS I could not connect to a static IP address (as I don't control the router) but I could see CIPSTA_CUR= executed correctly...

@star297
Copy link
Contributor

star297 commented Apr 1, 2020

Sounds like its working for you so no worries.
I'm testing this on Studio with your Mbed version so who knows if that's gonna work properly.
l can wait until it gets to merged to the official Mbed OS and try it from there.

@michalpasztamobica
Copy link
Contributor Author

I got a confirmation from @mtomczykmobica that the behavior is not exactly as I expected. I think this needs more debugging from my side. I will try to use RAAS, or test on my desk as soon as I have access to K64F+ESP8266 setup.

@mbed-ci
Copy link

mbed-ci commented Apr 7, 2020

Test run: FAILED

Summary: 3 of 3 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-GCC_ARM-lts
  • jenkins-ci/mbed-os-ci_build-ARM-lts
  • jenkins-ci/mbed-os-ci_unittests-lts

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 7, 2020

CI lts not related to this PR, will be cleared and proper CI restarted after 5.15 PRs are all integrated

@0xc0170
Copy link
Contributor

0xc0170 commented May 8, 2020

CI restarted

@mbed-ci
Copy link

mbed-ci commented May 8, 2020

Test run: SUCCESS

Summary: 6 of 6 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 merged commit 8e789b0 into ARMmbed:master May 13, 2020
@mergify mergify bot removed the ready for merge label May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESP8266 set_network static function not working.
6 participants