Multitasking with arduino mega 2560

We want to parallel record 3 sensor/switch data. Also after an interval of time send all this data to an enternal server using wifi ESP8266. but the problem is when i send data to server it takes 3-4sec . And during this time a lot of sensor data is missedout. The sensor output is after every 70 ms . And all sensor data is very important can’t miss any.

Now i want to do both operations simultaneously on arduino. Parallel record values and timely send the data to server over internet

I am using arduino mega2560 atmel microcontroller. So do all operation

Not without a bunch of buffering and interrupts.

No “multi-tasking” as you want it.

Time-slicing, yes. True “multi-tasking”? No.

You will need to set up several state machines to do a time-slice style of control.

Timer says to sample data and you process the inputs.

Timer says to process server data and it handles the next operation of that data sending / handshaking.

How much data are you sending when it takes 3-4 seconds? If you are sending less than 4/.07 = 58 bytes, you have a problem. Otherwise, use a circular buffer, at least large enough to handle two packets of data. Collect the sensor data in a timer ISR so that will happen regardless of what the ESP8266 is doing

/mike