Go Down

Topic: Problems using Bridge and Softwareserial together (Read 1 time) previous topic - next topic

muellerp

Feb 10, 2014, 07:11 am Last Edit: Feb 10, 2014, 08:00 am by muellerp Reason: 1
Hello,
I am useing a power meter that every second sends a data packet at 9600 baud via a serial interface. The YUN receives this data via software serial. TX is not used.
The received data are sent in one case directly to the Console. In the other case I use the YunsServer to request the data via REST query.
After a few cycles the Bridge behaves incorrectly (on both scenarios).
When using the console, the transmission after a few blocks aborts.
After some requests the YunServer provides only an empty response.
A certain success was achieved when I strictly separate the code of the serial side from the code of the Bridge.
After the error has occurred, there are also problems when transferring a new sketch.
Often, a reset is necessary.

But it works never really good.
Are there any known problems?
Are there any solutions?

My IDE ist 1.5.5-R2.
The Path with the "python -u" is applied

The power meter ist sending the data every second.

Update: After waiting some minutes the transmission recovers from his "sleep". But only for a few transmissions.

The code:
Code: [Select]

#include <SoftwareSerial.h>
#include <Bridge.h>
#include <Console.h>

//Buffer size from 64 to 256 increased
SoftwareSerial mySerial = SoftwareSerial (8,9); // RX, TX

String inputSerial = "";
char rChar = ' ';
long cntr = 0;
bool store = false;

void setup() {
 Bridge.begin();
 Console.begin();  
 while(!Console);
 
 inputSerial.reserve (600);
 
 mySerial.begin(9600);
 
 Console.println ("Success");
}

// ****************************************
// Main Loop
// ****************************************
void loop() {
 

 // Read and transmit
 while ((mySerial.available() > 0) && store) {
   rChar = (char) (mySerial.read() & 0x7F);
   inputSerial += rChar;
   if (rChar == '!') {
     store = false;
     Console.println (inputSerial);
     inputSerial = "";  
     }
 }
 
 // Read, but don not transmit
 while ((mySerial.available() > 0) && !store) {
   if ((char) (mySerial.read() & 0x7F) == '!') {
     cntr++;
     if (cntr > 2) {
       store = true;
       cntr = 0;
     }
   }
 }
 

 delay (20);

}



The data:
Code: [Select]

HAG5eHZ010C_IEnBWA02

1-0:0.0.0*255(38455910)
1-0:1.8.0*255(007511.9658)
1-0:96.5.5*255(82)
0-0:96.1.255*255(0000157847)
1-0:32.7.0*255(228.86*V)
1-0:52.7.0*255(230.61*V)
1-0:72.7.0*255(228.98*V)
1-0:31.7.0*255(001.70*A)
1-0:51.7.0*255(000.12*A)
1-0:71.7.0*255(000.26*A)
1-0:21.7.0*255(+00332*W)
1-0:41.7.0*255(+00011*W)
1-0:61.7.0*255(+00017*W)
1-0:96.50.0*0(EE)
1-0:96.50.0*1(07CF)
1-0:96.50.0*2(17)
1-0:96.50.0*3(10)
1-0:96.50.0*4(21)
1-0:96.50.0*5(06)
1-0:96.50.0*6(003E381B020B35F052345800009F80)
1-0:96.50.0*7(00)
!



muellerp

A little Step forward.
I have added two lines of code to my sketch:

Code: [Select]

      mySerial.end();
      Console.println (inputSerial);
      mySerial.begin (9600);


Now the transmission is more fluently.
The faltering is with the change gone too.

Not satisfied!

muellerp

Sorry for my soliloquizing.
Console ist now working with SoftwareSerial.
For YunServer I did not find a solution.

Now I'm using AltSoftSerial. Not my first choice, because of some drawbacks.
But I got it up and running.

Go Up