Jump to content
43oh

TM4C1294 ethernet library crashes


Recommended Posts

Hello all

I am building a temperature logging web server around a  TM4C1294 LP and several "temperature bugs", little sensors built around a MSP430G2553 and I2C temp sensors.

 

The web server is connected with these "bugs" via NRF24 modules.

(at the moment only one active)

 

The server logs the temperature data over long time and shows them on a table. 

Time is synced with NTP once an hour.

I am using Energia 16

 

Everything works fine and as expected

 

However, the whole system is not reliable. The more often I connect

via web browser, the more likely  it will simply not accept any connection and crash.

 

Sometimes o.k. for four days, sometimes crashed after 24 hours.

 

 

In order to trace down the problem, I inserted the auto-refresh:

 

  client.println("<META HTTP-EQUIV=\"refresh\" CONTENT=\"10\">");

 

 

Like this it is much worse, sometimes survive for an hour, sometimes crash after 15 minutes.

Having two or three browser tabs open make it worse.

 


Once crashed, no more communication over serial any longer. Only reset helps.

Heart beat LED 1 constantly off.


LED 2 and 3 are constantly on.

So it seems to get blocked in the printIndex function, which

mostly consists of client.println  calls. 

 

 

Any suggestions?

Is there anything I am doing wrong in my Ethernet code? (It is more or less copied from the example)

Anybody has a TM4C1294 Launchpad running 24/7 as a simple webserver with the ethernet library?

 

Thanks for any help or hint



// temperature logger web server
// Energia0101E0016, Board:tm4c129

#define temp_array 288
#define seconds_per_sample 600

#include <Ethernet.h>
#include <EthernetUdp.h>
#include <time.h>
#include <Enrf24.h>
#include <nRF24L01.h>
#include <string.h>
#include <SPI.h>

EthernetServer server(80);
EthernetClient client;

Enrf24 radio(8, 12, 11);
const uint8_t rxaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };
const uint8_t txaddr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x01 };

byte mac[] = { 0x00, 0x1a, 0xB6, 0x02, 0xa8, 0xc2 };
byte myip[]= { 192,168,1,54};

unsigned int localPort = 8888; // local port to listen for UDP packets

IPAddress timeServer(66,228,59,187);

const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

unsigned long oldmillis;
unsigned long oldepoch,epoch;

float temperature;
float temp24 [temp_array];
unsigned long time24 [temp_array];
int index24;
int timeout_to_sync=30;

// A UDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
Serial.begin(9600);
Serial.println("UdpNtpClient setup");

pinMode(D1_LED, OUTPUT);
pinMode(D2_LED, OUTPUT);
pinMode(D3_LED, OUTPUT);

SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
radio.begin(); // Defaults 1Mbps, channel 0, max TX power
radio.setSpeed(250000);
radio.setRXaddress((void*)rxaddr);
radio.setTXaddress((void*)txaddr);
radio.enableRX(); // Start listening

Ethernet.begin(mac,myip);
Udp.begin(localPort);
server.begin();
printEthernetData();
}

void loop() {
//read in temperature sensor (an MSP430G2553, sending the 2 bytes from an I2C temp sensor over NRF24)
//once a minute
char inbuf[33];
if (radio.read(inbuf)) {
Serial.print("Received radio packet: ");
Serial.println(inbuf[0]+inbuf[1]*256);
if (inbuf[1] >> 7) { // negative temperature value
temperature = float (((inbuf[1] << 1) | (inbuf[0] >> 7)) / 2 ) - 128;
}
else { // temperature value is positive
temperature = float ((inbuf[1] << 1) | (inbuf[0] >> 7)) / 2;
}
Serial.print("Temperature: ");
Serial.println(temperature);
}

//internet server starts here
client = server.available();
if (client) { // if you get a client,
digitalWrite(D1_LED, HIGH);
Serial.print("new client on port "); // print a message out the serial port
Serial.println(client.port());
String currentLine = ""; // make a String to hold incoming data from the client

boolean newConnection = true; // flag for new connections
unsigned long connectionActiveTimer; // will hold the connection start time
int timeoutimer=millis();
while (client.connected()) { // loop while the client's connected
if (newConnection){ // it's a new connection, so
connectionActiveTimer = millis(); // log when the connection started
newConnection = false; // not a new connection anymore
}
if (!newConnection && connectionActiveTimer + 1000 < millis()){
// if this while loop is still active 1000ms after a web client connected, something is wrong
break; // leave the while loop, something bad happened
}
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.print(c);
if (c == '\n') { // that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0) {
break;
}
else { // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r') { // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
if (currentLine.endsWith("GET / ")){
digitalWrite(D2_LED, HIGH);
printIndex();
digitalWrite(D2_LED, LOW);
}
}
}
client.stop();
digitalWrite(D1_LED, LOW);
}

// one second tick
if (millis()>=(oldmillis+980)) digitalWrite(D3_LED, HIGH);
if (millis()>=(oldmillis+1000)){
oldmillis=millis();
epoch++;
digitalWrite(D3_LED, LOW);

//sample the temperature into an array every now and then
if(epoch%seconds_per_sample==0){
index24++;
if (index24>=temp_array) index24=0;
time24[index24]=epoch;
temp24[index24]=temperature;
}

//short time after startup, then once an hour, sync with time server

timeout_to_sync--;
if(timeout_to_sync==1){
Serial.println("prepare sync with time server...");
sendNTPpacket(timeServer); // send an NTP packet to a time server
}
if (!timeout_to_sync){
timeout_to_sync=3600;
if ( Udp.parsePacket() ) {
// We've received a packet, read the data from it
Serial.println("we got a signal...");
Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer

unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
// combine the four bytes (two words) into a long integer
// this is NTP time (seconds since Jan 1 1900):
unsigned long secsSince1900 = highWord << 16 | lowWord;
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
const unsigned long seventyYears = 2208988800UL;
// subtract seventy years:
epoch = secsSince1900 - seventyYears;
epoch+=3600; //we are not in greenwich; +7200summmer, +3600winter
oldepoch=epoch;
}
else{
Serial.println("sync failed!");
}
}
}
}

void printIndex(){
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.println("<html><head><title>Maelli 02</title></head><body align=left>");
client.println("<h1> <font color=\"red\">my little temp logger</font>");
client.println("<h2> <font color=\"green\">Current date is "); // UTC is the time at Greenwich Meridian (GMT)
timeprint(epoch);
client.println("</br><font color=\"blue\">Temperature now is: ");
client.print(temperature);
client.print(char(176));
client.println("C</font></h2>");

int index=index24+1;
for (int a=0; a<temp_array; a++){
if (index) index--;
else index=index+(temp_array-1);

timeprint(time24[index]);
client.println(" - ");
client.print(temp24[index]);
client.print(char(176)); //
Link to post
Share on other sites

I experimented with mine using Exosite and had issues similar to what is discussed in the TI E2E thread referenced below.  With the patch referenced late in the thread it did improve but I ended up putting it aside, deciding to wait until the stability issues were more fully addressed over time.

 

http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/358842/1296816#1296816

 

For further reading you may want to visit http://e2e.ti.com/support/microcontrollers/tiva_arm/  and type:  connected Launchpad in the search field.  Although not specifically addressing use of this Launchpad under Energia, perhaps it could be helpful.

Link to post
Share on other sites
  • 1 month later...

Reading this discussion on e2e.ti.com does not give me a good feeling. Seems like nobody wants to solve the problem or even admit there is one :-(

 

meanwhile I added a watchdog (4secs) into my code. I feed the dog after the client.print function calls.

 

The watchdog triggers more often than not.

I have the strong feeling that sometimes the 

 

client.print(xx);

 

function gets stuck in nowhereland for ever.

 

Not good. With the device resetting every now and then, I cannot log any data.

Link to post
Share on other sites

Hi,

 

I am experiencing the same kind of issues, my TM4C1294 works as a hub to the IOT for an RF network of sensors. Sometimes it just stops working and needs to be reset. I am now using a 60second watchdog and this catches the random freezes.

 

cheers

 

Cor

Link to post
Share on other sites
  • 1 year later...

had this thing now running 24/7 for more than a year. 

Each time the ethernet library crashed, watchdog would trigger, count up one and restart the board.

 

It crashed 32 times in the last 12 months.  ;-)    not often, but often enough to be a useless bit of kit.

 

Has the problem been solved in the meantime? I have not been looking around in the forum much, but I have the impression that I am/was not the only one with issues.

 

Could it make sense to upgrade to the latest energia?

Link to post
Share on other sites
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...