zarobhr

IDE 1.02, UNO R3, also have LCD and a 12 key keypad0-9 and 'E' and "C'I am writing a routine to allow a user to enter an IP address on the UNO if there is not one already entered. I have only included the code for this section

just curious if anyone sees a way to make more compact , not written in yet is the capturing of the ip and storeing it to eeprom. i would like suggestions on the most feasable way to do and also a suggestion on a way to validate whether it is a valid ip address. I have thought about validateing as it is entered for exampleABC.ABC.ABC.ABC , when A is intered only allow 0 1 or 2 to be entered and if user press three force it back to a 2. then when B is entered , allow 0-9 if A is 0 or 1 but only allow 0-5 if A = 2.the other way is to allow anything to be typed and then when 'E' on keypad is pressed do sometype of check. what are your thoughts.here is code so far

You need a char array. Every time you adjust the printing position on the LCD and print a character, store the character in the corresponding position of the array. Remember that array indexes, like LCD column positions, start at 0.

The art of getting good answers lies in asking good questions.

zarobhr

You need a char array. Every time you adjust the printing position on the LCD and print a character, store the character in the corresponding position of the array. Remember that array indexes, like LCD column positions, start at 0.

so i created the array and i am filling it as the keys are pressed ( in the code if 'E' is pressed it moves the cursor to the right unless it is in last position then it will just print the array on line one of lcd for testing.

I also am checking for valid ip as it is entered.

what i would really like to do is take each part of the ip address that is in array for example ip address 123.145.167.189 is 15 chars in array, when i store to eeprom i want to write as 4 bytes so how do i go about converting portions of the array to a byte

PeterH

There are already types defined to hold IP addresses in the common ethernet libraries. Have you checked whether there are also library functions to parse a dotted decimal string into an IPv4 address? I would be surprised if there wasn't.

If you can't find anexisting implementation and want to roll your own, the way I'd tackle this problem is to split the input string into four sequences of decimal digits, convert each sequence of digits to a number and verify the number is in the range 0 .. 255. I'd return the result using the existing IP address type, although I suppose you could use a 32-bit int instead.

IPaddr[IPpos - 1] = key; IPaddr[IPpos] = '\0';to keep the string NULL terminated.the last 16th position has the null, if i try like this and you backspace with c and change the value the null moves and i need to keep null at the end

When the 'E' key is pressed, you need to use the strtok() and atoi() functions to get the tokens (the parts between the dots) and convert them to numbers.