cancel
Showing results for 
Search instead for 
Did you mean: 

LwIP: set IP address, mask, and Gateway address of stm32 remotely

abeba.1
Associate III

hii every one 

 

i have a question about setting up the ip of the STM32 MCU remotely 

 

when we want to do client server in udp or tcp on stm32 controller , we are used to set the ip address manually in the ioc file in general settings in the lwip section in the middleware tab .

 

and i was wondering if there is a way to set up any default ip of mine , and is there a way to change this ip remotly after i am connected to the stm32 .

 

my goal is to design an application that can give me the ability to access and change the ip and mask and gateway of my stm32 controller , i be very thankful for help and to know if there is a method to do that  

20 REPLIES 20

this process is called reservation , and its done at the level of the dhcp server 

Yes, exactly.

my local network needs to have a dhcp server in order to do the ip reservation , am i right ?  

Yes again

 i am not the administrator of the dhcp server on the network

Then, no luck with the dhcp server.

-is there away of accessing the configurations of the dhcp server on my network with terminal commands to put my stm32 mac address and my desired ip  

Try to ask this your IT person or network admin - but be careful, they may get angry and violent.

hii pavel thanks for help :)

 

is there away to set the ip on the level of the stm32  , not using dhcp , i will tell what i need maybe you will understand me 

 

for example there are ethernet to serial converters like moxa that have GUI that enable me to set the ip address that i want .

i put default ip address to access the moxa GUI in the browser and then i will do my desired ethernet configuration changes , and my question is there a similar way to do this operation with the STM32 controller

 

Please don't start multiple threads on the same question.

To un-mark a solution, see:

https://community.st.com/t5/community-guidelines/help-others-to-solve-their-issues/ta-p/575256#:~:text=If%20you%20accidentally%20chose%20the%20wrong%20post%20as%20solution%2C%20you%20can%20always%20revert%20this%20action%20by%20clicking%20%22Not%20the%20Solution%22

 


@abeba.1 wrote:

lets say that my board is connected to the network the dhcp server is out of my reach , i am not the administrator of the dhcp server on the network   


In that case, you shouldn't be manually setting IP addresses anyhow - the address might already be used by something else on the network!

 


@abeba.1 wrote:

 means that my local network needs to have a dhcp server in order to do the ip reservation , am i right ?   


Yes.

 

If only I understand correctly about this moxa thing. Of course if there's a "side channel" to the STM32, thru a UART and so on, you can use that to command the STM32 to set the specified address. Do you have such side channel?  There are also various hacky ways using "magic packets" with the MAC address of the target, but they are not standard. Use on your own risk.

 

hii pavel yes i can set a uart as side channel.

how can i use this side channel to set the specified address on the stm32 do have an example , thanks for help i think that your suggestion is what i really need 

For example you can listen on the UART for message from the PC. Something like "set ip 1.2.3.4/24\n" .

When you get it, change the IP address as specified.

Here you can find help with coding and advice on general networking topics.

 


@abeba.1 wrote:

how can i use this side channel to set the specified address on the stm32  


There are 2 separate issues here.

  1. How to use a UART to receive commands to the STM32;
  2. How to set the IP address.

The two are independent.

So start by just working on the UART to accept commands, and give responses.

Presumably, this will interact with a human user at a terminal?

So maybe have commands like

  • IP=
  • MASK=
  • GATEWAY=

to set the IP address, Mask, and Gateway address.

So that's a simple matter of collecting characters from the UART, and then parsing strings.

Define a terminator character - such as CR - then collect characters until you get that terminator.

Once you've got the terminator, you parse the received characters as a string.

To work with a human operator, you'll need to give a reply - such as "OK" or an informative error message.

You'll probably also want a way for the operator to find what the current settings are; perhaps

  • IP?
  • MASK?
  • GATEWAY?

Or just the command with no parameter

  • IP
  • MASK
  • GATEWAY

Once you've collected the values from your user interface, you then just set them through the appropriate APIs to your network stack.

 

PS:

Pseudo-code:

REPEAT
get a character from the UART
append it to a buffer
UNTIL character is CR

replace the CR with NUL (C string terminator)
parse the string (using standard C library functions)

IF successfully parsed
give "success" response
apply the setting
ELSE
give "error" response

 

This is the kind of thing that can easily be prototyped & tested just on a "normal" computer - no need for any target hardware!

hii pavel thank for your reply and help

 

if i understand you right and translate your explanation into code :

i need to define a global variable that can store the ip address and when i get the message from the uart.

i need to find a way to extract the ip address from the uart message and assign it to the global variable that i defined. 

lets say for example i define 4 global variables:

 ip_ad1

ip_ad2

ip_ad3

ip_ad4

and then use this global variable in in the struct that defines the ip 

lets say for example that i managed to extract from uart message 

 

ip_ad1=192

ip_ad2=168

ip_ad3=1

ip_ad4=100

i need to use IP4_ADDR macro to set the the new ip that i received from uart 

ip_addr_t ipaddr;
IP4_ADDR(&ipaddr, ip_ad1, ip_ad2, ip_ad3, ip_ad4);

and that leads me to a question , after this operation do i need to recompile the code ? my goal is change the ip with the help of a uart as side channel without the need to compile .

cause if i use static dhcp configuration and i define the ip address in the ioc i need to compile the project  that what we do normaly 

again thanks for help:)

hii andrew  thank for help also :) your explanation made more clear to me  , i will also ask you this question after this process that you described 

is applying the setting  with the appropriate APIs to your network stack require me to compile the project cause my goal is to receive the ip from the uart and change the ip settings of the stm32 online with out the need to compile 


@abeba.1 wrote:

i need to define a global variable that can store the ip address and when i get the message from the uart.:)


It doesn't necessarily need to be global.

 


@abeba.1 wrote:

after this operation do i need to recompile the code ? 


No. That's the whole point of variables - they hold things which vary at run time!

 


@abeba.1 wrote:

if i use static dhcp configuration and i define the ip address in the ioc i need to compile the project 


In that case, you're not using DHCP at all - you're just using a hard-coded constant.