-1

I have question similar to old topic here Any way to pass EthernetClient to function outside of loop automatically?

I have in the main loop opening of the TCP server which is just maintaining the connection, but I need to send data from the interrupt rutine.

Can anybody tel me how to declare the connection globaly to be able to reference from event rutine and not from main loop only?

Thank you

  • 4
    That's probably a bad idea - this is far too involved and lengthy a task to safely perform in an ISR. What you should do is set a volatile flag in the ISR to indicate to the main program loop that it would be appropriate to send some data. – Chris Stratton Feb 6 '18 at 21:19
  • 1
    use globals to store the data to be sent, and a flag that indicates data is ready, then check the global in loop() and response accordingly; it won't take a lot of extra time... – dandavis Feb 6 '18 at 21:43
  • I need to stream data as much synchronous as possible so I'm looking for a way how to send it from ISR directly. Thanks anyway. – jan tkany Feb 6 '18 at 22:22
  • 1
    @jantkany - then you shouldn't be using TCP to begin with. Doing this in an ISR is not going to work, and the delay of doing it in the main loop will be well within the norms of TCP traffic, if your program is well structured. – Chris Stratton Feb 6 '18 at 23:42
  • No surgery in the dr's office, you get the diagnosis and schedule an appt with a surgeon. – dandavis Feb 7 '18 at 20:48
2

You don't, instead you set a volatile flag in the interrupt routine and/or append to a circular buffer and handle the actual sending the next time through in your main loop.

The time delay from deferring action from the ISR to the main loop code will be on the order of milliseconds, if that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.