This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

EK-TM4C1294XL: changing ip of TM4C1294 and rebooting ethernet

Part Number: EK-TM4C1294XL
Other Parts Discussed in Thread: ENERGIA

Hi all!

I started a tcp server on my TM4C1294. I want to change the ip of ethernet  and restart my server with the new ip. For this reason, I tried the below code...

<

Serial.println("\nserver rebooting-1");

server.available().stop();
Serial.println("\nserver rebooting-2");
delay(100);

Ethernet.begin(mac, ip_arr, dns_arr, gw_arr, mask_arr);

delay(100);
Serial.println("\nserver rebooting-3");
server.begin();

>

Unfortunately, the program stuck in "Ethernet.begin". 

Is there anything in order to restart the ethernet and tcp server with new ip?

  • Can you tell me where your example code came from so that I can direct your question to the correct person?
  • Hi Bob,

    I coded the code myself.

  • I'm sorry, my question was unclear. Are you using Energia? If not, where did the "server.begin()" function come from?
  • Hi Bob,
    Sorry for the inconvenience. I'm using energia.
    I first initialize ethernet server with a default ip, gateway, subnet in setup.
    From serial port, it gets new IP, new GW and subnet values. After getting new values for IP, GW, subnet and dns, I am trying to restart ethernet connection with new values.

    Thanks for your time!

    Here is my entire code:

    //*************************************************************************************
    //LIBRARIES
    #include <stdint.h>
    #include <stdbool.h>
    #include "inc/hw_memmap.h"
    #include "driverlib/debug.h"
    #include <Ethernet.h>
    #include <Wire.h>
    #include "driverlib/pin_map.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/i2c.h"
    #include "inc/hw_i2c.h"
    #include "inc/hw_types.h"
    #include "XIO.h"
    #include "string.h"


    byte mac[] = { 0x00, 0x1A, 0xB6, 0x02, 0xF0, 0x80 };

    int PortNumber = 1234;
    byte ip_arr[] = { 162, 98, 0, 06 };
    byte dns_arr[] = { 162, 98, 1, 1 };
    byte gw_arr[] = { 162, 98, 1, 1 };
    byte mask_arr[] = { 255, 0, 0, 0 };
    EthernetServer server = EthernetServer(PortNumber);

    // IO EXPANDER PCA9698 Class define U1 to U7 chips
    XIO tempU[7] ;//{U1, U2, U3, U4, U5, U6, U7};

    int IOselect [5] [8] { //initialize to zero
    {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07},
    {0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17},
    {0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27},
    {0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37},
    {0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47},
    };


    void setup() {
    Serial.begin(19200);
    Ethernet.begin(mac, ip_arr, dns_arr, gw_arr, mask_arr);
    server.begin();
    delay(100);
    }

    int serial_read_data[25];
    int serial_index = 0;
    void get_serial_data(String serial_data)
    {
    unsigned char incomingByte;
    char *sr_data = &serial_data[0];
    char str[40];
    //char *tab2 = new char [serial_data.length()+1];
    byte ip1 = 0;
    byte ip2 = 0;
    byte ip3 = 0;
    byte ip4 = 0;

    if(serial_data == "show" )
    {
    Serial.print("IP = ");
    Serial.println(Ethernet.localIP());
    Serial.print("Subnet = ");
    Serial.println(Ethernet.subnetMask());
    Serial.print("Gateway = ");
    Serial.println(Ethernet.gatewayIP());
    Serial.print("Port = ");
    Serial.println(PortNumber, DEC);
    }
    else if(serial_data == "U" )
    {

    Serial.println("\nserver rebooting-1");
    server.available().stop();
    Serial.println("\nserver rebooting-2");
    delay(100);

    Ethernet.begin(mac, ip_arr, dns_arr, gw_arr, mask_arr);//STUCKS!!!!!!!!



    delay(100);
    Serial.println("\nserver rebooting-3");
    server.begin();
    Serial.println("\n server rebooted...");
    Serial.print("IP = ");
    Serial.println(Ethernet.localIP());
    Serial.print("Subnet = ");
    Serial.println(Ethernet.subnetMask());
    Serial.print("Gateway = ");
    Serial.println(Ethernet.gatewayIP());
    Serial.print("Port = ");
    Serial.println(PortNumber, DEC);
    }
    else
    {
    //char serial_data[serial_data.length()];
    //strcpy (tab2, serial_data.c_str());
    memset(str, '\0', sizeof(str));
    strncpy ( str, sr_data, 3);
    if(strcmp(str, "IP=") == 0)
    {
    Serial.println("\nIP Changing!!");
    ip1 = 100 * (sr_data[3] - 0x30) + 10 * (sr_data[4] - 0x30) + (sr_data[5] - 0x30);
    ip2 = 100 * (sr_data[7] - 0x30) + 10 * (sr_data[8] - 0x30) + (sr_data[9] - 0x30);
    ip3 = 100 * (sr_data[11] - 0x30) + 10 * (sr_data[12] - 0x30) + (sr_data[13] - 0x30);
    ip4 = 100 * (sr_data[15] - 0x30) + 10 * (sr_data[16] - 0x30) + (sr_data[17] - 0x30);
    Serial.println(ip1, DEC);
    Serial.println(ip2, DEC);
    Serial.println(ip3, DEC);
    Serial.println(ip4, DEC);
    ip_arr[0] = ip1;
    ip_arr[1] = ip2;
    ip_arr[2] = ip3;
    ip_arr[3] = ip4;
    }
    else if(strcmp(str, "SN=") == 0)
    {
    Serial.println("\nSubnet Changing!");
    ip1 = 100 * (sr_data[3] - 0x30) + 10 * (sr_data[4] - 0x30) + (sr_data[5] - 0x30);
    ip2 = 100 * (sr_data[7] - 0x30) + 10 * (sr_data[8] - 0x30) + (sr_data[9] - 0x30);
    ip3 = 100 * (sr_data[11] - 0x30) + 10 * (sr_data[12] - 0x30) + (sr_data[13] - 0x30);
    ip4 = 100 * (sr_data[15] - 0x30) + 10 * (sr_data[16] - 0x30) + (sr_data[17] - 0x30);
    Serial.println(ip1, DEC);
    Serial.println(ip2, DEC);
    Serial.println(ip3, DEC);
    Serial.println(ip4, DEC);
    mask_arr[0] = ip1;
    mask_arr[1] = ip2;
    mask_arr[2] = ip3;
    mask_arr[3] = ip4;
    }
    else if(strcmp(str, "GW=") == 0)
    {
    Serial.println("\nGW Changing!!");
    ip1 = 100 * (sr_data[3] - 0x30) + 10 * (sr_data[4] - 0x30) + (sr_data[5] - 0x30);
    ip2 = 100 * (sr_data[7] - 0x30) + 10 * (sr_data[8] - 0x30) + (sr_data[9] - 0x30);
    ip3 = 100 * (sr_data[11] - 0x30) + 10 * (sr_data[12] - 0x30) + (sr_data[13] - 0x30);
    ip4 = 100 * (sr_data[15] - 0x30) + 10 * (sr_data[16] - 0x30) + (sr_data[17] - 0x30);
    Serial.println(ip1, DEC);
    Serial.println(ip2, DEC);
    Serial.println(ip3, DEC);
    Serial.println(ip4, DEC);
    gw_arr[0] = ip1;
    gw_arr[1] = ip2;
    gw_arr[2] = ip3;
    gw_arr[3] = ip4;
    }
    else
    {
    strncpy ( str, sr_data, 5);
    if(strcmp(str, "Port=") == 0)
    {
    Serial.println("\nPort Changing!!");
    PortNumber = 10000 * (sr_data[5] - 0x30) + 1000 * (sr_data[6] - 0x30)
    + 100 * (sr_data[7] - 0x30) + 10 * (sr_data[8] - 0x30)
    + (sr_data[9] - 0x30);
    Serial.println(PortNumber, DEC);
    }
    }
    }
    }

    //int i=0;
    void loop() {

    if (Serial.available() > 0) {
    // read the incoming byte:
    String incomingByte = Serial.readString();


    get_serial_data(incomingByte);
    }
    }
  • Hello Oguzhan,
    We do not really support Energia for the TM4C on the E2E forum. Now that "Energia" is added to the tags, some other user may be able to jump in and help. Also, you can go to the Energia support forums for assistance with this issue:
    forum.43oh.com/.../
  • ok. thanks for your time.

    BR,

    Oguzhan