Hi,
I’m using WiFly to send data over Wifi to a Max/MSP application. The smaller data frames are 8 bytes long and are sent every 10 ms.
The problem is that sometimes the datas are bufferised and send as group of 2 to 5 frames instead of single frames every 10 ms. There is an exemple below of what I received in Max/MSP :
0ms - a 8 byte frame
10ms - a 8 byte frame
20ms - a 8 byte frame
100ms - a 8x8 byte frame
So I loose my data stream for 90 ms / 9 frames and sometimes more and don’t understand why. I’ve try many flush time and flush size settings as well as hardware flow control but nothing seems to works flawessly. I got better results with a flush time of 1ms and a flush size of 512 bytes but still have lags as describe just above.
Here is the code I use from a Teensy 3.1 connected to the WiFly module.
//////////////////////////
// librairies utilisées //
//////////////////////////
#include <Metro.h>
#include <EEPROM.h>
#define ENCAPS 7
#define ID 1
#define RTS_PIN 7 // RTS2 vers CTS2
#define CTS_PIN 8 // CTS2 depuis RTS2
byte buffer[264];
//////////////////////////////
// instanciations d'objets //
//////////////////////////////
Metro FFTMetro = Metro(10);
//////////////////////////////////
// initialisation du programme //
//////////////////////////////////
void setup()
{
Serial1.begin(115200);
pinMode(RTS_PIN,OUTPUT);
pinMode(CTS_PIN,INPUT);
}
//////////////////////////////////
// initialisation du programme //
//////////////////////////////////
void loop() {
if (FFTMetro.check()==1) {
/*digitalWrite(RTS_PIN,LOW);
while(digitalRead(CTS_PIN)!=LOW){
}*/
sendVolume();
Serial1.println();
/*digitalWrite(RTS_PIN,HIGH);
while(digitalRead(CTS_PIN)!=HIGH){
}*/
}
}
void sendVolume() {
word l = 1;
starter(203);
buffer[3]=highByte(l);
buffer[4]=lowByte(l);
for (word i = 0; i<l; i++) {
buffer[i+5]=random(0,255);
}
ender(l);
Serial1.write(buffer,l+ENCAPS);
}
void starter(byte CMD) {
buffer[0] = 231;
buffer[1] = ID;
buffer[2] = CMD;
}
void ender(word l) {
long sum = 0;
for (word i = 0; i < l+4; i++) {sum += buffer[i+1];}
buffer[l+5] = sum%256;
buffer[l+6] = 126;
}
Is there a way to force data sending or to configure the module to send data as soon as possible ?
Sincerely
SYLVAIN