Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Arduino Ethernet (U...
 
Share:
Notifications
Clear all

[Solved] Arduino Ethernet (UIPEthernet) crashes

8 Posts
2 Users
0 Reactions
2,337 Views
(@psman)
Active Member
Joined: 9 years ago
Posts: 5
Topic starter  

Hi,

I came across this website //www.tweaking4all.com/hardware/arduino/arduino-ethernet-data-push/ and wanted to test the code - with some parts of the code I did try to upload integers and decimals to a mysql-database. It worked fine!

In addition wrote a code for some measurements – the analysis of
the data and showing it at the serial monitor works as well!

Finally I wanted to merge this two codes and to send the data via a function called "DatenSenden()".

void DatenSenden()
{
#ifdef DEBUG
Serial.print("MillisDifferenz: ");
Serial.println(MillisDifferenz);
Serial.print("Sonde 1:\t");
Serial.print(counts1,DEC);
Serial.print(" ips,\t");
Serial.println(cpm1,2);
Serial.print("Sonde 2:\t");
Serial.print(counts2,DEC);
Serial.print(" ips,\t");
Serial.println(cpm2,2);
#endif

#ifdef DEBUG
Serial.println("connecting...");
#endif

if (client.connect(server, 80)) {
#ifdef DEBUG //should show, that all the parameters for the connection are avaiable
Serial.print("localIP: ");
Serial.println(Ethernet.localIP());
Serial.print("subnetMask: ");
Serial.println(Ethernet.subnetMask());
Serial.print("gatewayIP: ");
Serial.println(Ethernet.gatewayIP());
Serial.print("dnsServerIP: ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("connected..."); Serial.println("");
#endif
client.print("GET /upload_data.php?zuluft=");
client.print(cpm1);
client.print("&&abluft=");
client.print(cpm2);
client.print(" HTTP/1.0\r\n");
client.print("Host: ");
client.print(server);
client.println("\r\nConnection: close\r\n\r\n");
client.stop();
} else {
#ifdef DEBUG
Serial.println("connection failed");
#endif
}
}

Typically the code is working properly until it reaches

Serial.println(cpm1,2);

This decimal-number is partly printed, the point is the last
character I do see in the serial monitor. The variable itself is  avaiable in the function – if I do add the “Serial.print”-part several times, the data is written properly several times.

If I do
leave away the “Serial.print”-part, the controller again crashes several
lines above the “client.connect”-part.

Has anybody had a similar problem? (For sure I can upload the full code as well - unfortunately I could not create a smaller example with a similar problem).

Thanks a lot!


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Hi psman,

Excellent that you tried the forum! 
Unfortunately I had not seen this post until after I answered you question under the article.

As far as I recall, printing float/double variables can cause issues when using print and println.

See for example this topic in the Arduino forum.

Hope this helps. 


   
ReplyQuote
(@psman)
Active Member
Joined: 9 years ago
Posts: 5
Topic starter  

Hello Hans,

thank you very much for this hint!

I changed the data-type of all variables to "unsigned long" (I don't really need the decimal place). The code again crashed - now it always stops with " i" instead of writing " ips".

I'm a bit helpless with this problem. Would it be easier to find the fault, if I uploaded the full code?

Thanks for every help!

P.S: Could you please delete my post at //www.tweaking4all.com/hardware/arduino/arduino-ethernet-data-push/? It's not necessary any more..


   
ReplyQuote
(@psman)
Active Member
Joined: 9 years ago
Posts: 5
Topic starter  

I have uploaded the full script in the attachment..


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Hi PsMan,

I'm beginning to suspect that it might have to do with the "volatile" statement you use in the variable declarations in the beginning.
Granted, I have never used "volatile" or interrupts.

You could try this, to see if makes a difference: temporary copy the value of cpm1 to a "normal" variable:

...
unsigned long cpm1_copy = 0;
...
void setup() {
  ...
}
void loop () {
 ...
    cpm1_copy = cpm1;
    Serial.println(cpm1_copy,2);
  ...
}

I'm not sure if this will fix the issue, I'm just thinking that a volatile variable might be an issue for serial.print since it's stored differently.


   
ReplyQuote
(@psman)
Active Member
Joined: 9 years ago
Posts: 5
Topic starter  

Hello again!

"Volatile" has been recommended for interrupt-routines. Just to be sure, if this causes the problem, I have implemented volatile variables to my small web-client-example. It still worked fine.

I thought, that I would run out of memory. That's why I tested the code on an Arduino Mega instead of the Nano with no improvement.

Does anyone have an idea, why serial.print-lines are effected by ethernet.connect that should work afterwards? Or is there someone whom I could ask for help?

Thanks a lot!


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

I have done some reading up and it seems the use of interrupts actually interrupts the serial handling.

See also: StackOverflow - Arduino - Using interrupts freezes processing and serial output?

From that topic:

The problem here is that you cannot use:

Serial.Print()

Within an interrupt service routine. The reason that the Serial.Print() doesn't work within an ISR is that it uses interrupts to pull the characters out of the serial buffer, but interrupts of a certain level are masked within the ISR. What basically happens is that the arduino throws out all other interrupts that are of a lower priority, which Serial.Read() falls into.

It is documented in a number of places: link1, link2, link3

In all honesty, I never worked with interrupts on an Arduino.
Seems that you either have to stop the interrupt part, do the serial part, and then restart the interrupt.
Or ... abandon interrupts all together ... 


   
ReplyQuote
(@psman)
Active Member
Joined: 9 years ago
Posts: 5
Topic starter  

Thank you very much for this hint - that's the solution! With this knowledge I can bypass the problem!

Thank you for your profound help and for this interesting page!

Have a nice day,

psman


   
ReplyQuote
Share: