chipKIT® Development Platform

Inspired by Arduino™

ChipkitMax+Network Shield

Created Sat, 28 Mar 2015 05:31:06 +0000 by betomax


betomax

Sat, 28 Mar 2015 05:31:06 +0000

Hello I've a test program (Derived from TCPEchoClinet Wifi Demo) that upload a variable [Temperature from a 1-Wire] sensor to Ubidots Service [Using API REST]

but after a while the connection is lost, there is a lapse between sample uploads of ~60 Seconds, i noted that if this window time is shorter than ~10 Seconds the samples load succesfully, but if there are more than 60 seconds of so, the conection were lost

so, according to ChipKitEthernetTCPandUDP.pdf description i should broke long delays and make calls to EthernetPeriodicTasks() function, and i did, guess what?, still losing connection, anyone have some advise?

thanks, here is the main loop

void loop()
{
  
  int retvalues=50;
  sensors.begin();
  int timed_delay;
  int minutes_upload;
  const int period_upload=1;
  delay(100);
  sensors.requestTemperatures(); 
  float tempC = sensors.getTempCByIndex(0);
  int value = analogRead(A0);
  Serial.println("Sending Temp: ");
  Serial.print(tempC);
  Serial.println("");
  save_value(String(tempC));
  // delay broke by 60 secs and call Stack
  for(minutes_upload=0;minutes_upload <=  period_upload;minutes_upload++){
  for(timed_delay=1;timed_delay<=60;timed_delay++){
  if(minutes_upload==period_upload) break;
  delay(1000);
  Ethernet.PeriodicTasks();
  Serial.println(" Looping t_d "+ String(timed_delay)+" & m_d "+String(minutes_upload) + " period " + String(period_upload));
   }
  }
  
}

MarshallW

Tue, 19 Jan 2016 22:51:33 +0000

Hello Betomax,

I found your support question when I was looking through old posts in the forum. Sorry about the delay.

After looking through your code, there are a couple things to avoid:

  • blocking calls.
  • redeclarations of frequently used variables in the operating loop
  • generally avoid floats if you can (but not a horrible thing to do)

In this case when you are maintaining the TCP/IP stack, the delay() calls can cause the TCP/IP to timeout. If you just want to update the Ubidots service once a minute, then use a non-blocking system. A good example is the built in demo for blink without delay.

I don't normally do this but I rewrote some of your code so you can see exactly what I mean.

Hopefully you found a solution to your problem and I am sorry that you got lost.

int last_temp_reading, value;
float tempC;

setup(){
	last_temp_reading = 0;

	//unless you are beginning and ending in the operation loop
	//move to setup()
	sensors.begin(); 
}

void loop()
{
	if(millis() - last_time > 60000){
		last_temp_reading = millis();

		sensors.requestTemperatures(); 
		tempC = sensors.getTempCByIndex(0);
		value = analogRead(A0);

		Serial.println("Sending Temp: ");
		Serial.print(tempC);
		Serial.println("");

		save_value(String(tempC));
	}

	Ethernet.PeriodicTasks();
}

Best of luck, Marshall