Go Down

Topic: Bridge is slow, speed boost not 21,950% but 1,000,000% from Bridge. (Read 4578 times) previous topic - next topic

tim9510019

ATmega32u4 code:

Code: [Select]
void setup() {
  Serial1.begin(115200);
}
void loop() {
  while (true) {
    if (Serial1.available()) {
      int c = Serial1.read();
      if (c == '~') {                 //    Tilde '~' key pressed  for start sampling?
        while (Serial1.read() != -1);
        break;
      }
    }
    delay(10);
  }
  for ( unsigned long  i = 0; i <= 4294967295; i++) {
    Serial1.print(i);
    Serial1.print(',');
    Serial1.println(random(1023));
    Serial1.flush();
    if (Serial1.available()) {
      int c = Serial1.read();
      if (c == '^') {                 //   '^' key pressed for stop?
        break;
      }
    }
    delayMicroseconds(100);
  }
}


ser2net seems to be much faster than client & console.

I wanna know how to write the arduino code in ser2net style to achieve  REST API functions?

ShapeShifter

ser2net seems to be much faster than client & console.
Yes, on the positive side, it is much faster than the Bridge Library's Console class.

But on the negative side, it prevents using any of the Bridge Library's functions. While the Bridge Library is not a speed demon, it can do many different things, and do them all at once. ser2net is very fast, but it's a one trick pony - it replaces the Console class and nothing else.

Quote
I wanna know how to write the arduino code in ser2net style to achieve  REST API functions?
I'm not sure it's possible, that's not what ser2net was designed to do. Using ser2net means giving up the Bridge Library, which is what makes implementing a REST API in a sketch so easy. It makes it easy because there is code running on the Linux side which intercepts any requests to its web server that start with the token /arduino/. It takes such requests, and uses the Bridge Library to pass them to a YunServer object in the sketch, which creates a YunClient object to handle the actual request. At this point, all of the overhead of the request has already been handled, and just the remaining part of the URL (the part after /arduino/) is passed to the sketch. The sketch sends back a response through the YunClient object, and the Bridge Library and the code on the Linux side takes that response and adds in all of the overhead necessary to format it as a proper web request response.

If you want to do the same thing in a sketch while using ser2net, you will have to do all of that overhead processing that is currently being done on the Linux side - basically, you will need to write a web server inside of your sketch. Definitely a daunting task, with no assurance that it will actually work. I've written mini web servers before to handle specialized requests, and I don't think I would want to try it given the limited code space and RAM that is in the '32U4 processor that runs the sketch.

The other option is to implement your REST API on the Linux side, which eliminates the speed issues on the serial port between the two processors. There are many ways to do this, but I've had good luck using the Bottle Framework with some Python code. Of course, if the REST API needs information from the sketch (or sends information to the sketch) then you will have to have some way to do that - I typically use a Bridge Library Process object to do that, but one could use Bridge.put() or Bridge.get() or some other method. However, if you are using ser2net, you can't really use any of those other methods, and you may be in trouble.

ser2net is a wonderful replacement for the Console class, but it comes with some serious downsides. If all you need is a fast Console replacement, this is your ticket. But if you want to implement a REST API, I think it will only cause you heartache.

tim9510019

ShapeShifter, thanks for your reply.

Since using ser2net style to achieve REST API functions is really painful, one question came to my mind.

Does it exist another way to control arduino pins on the website with ser2net code?


ShapeShifter

Does it exist another way to control arduino pins on the website with ser2net code?
On what web site? One hosted by the Yun? If so, I simply don't see where ser2net would buy you anything at all. ser2net allows a remote computer to talk serial communications with the sketch over the network. I don't see where it has anything interesting to offer to you, unless the web site is hosted by another computer, and that computer is fielding the REST API and turning it into serial commands that are sent to the sketch over ser2net. You would be pretty much bypassing the Linux side of the Yun, which is an unfortunate thought since that is what gives the Yun so much power.

Rather than being hung up on ser2net and trying to figure out how to make it do something that it was not intended to do, you would be better off describing what you are actually trying to do. So far, all I can guess is that you want to control some pins with a website, and you are concerned about speed. But that's not nearly enough to go on to make and recommendations. What is hosting the web pages - the Yun? How complicated are the pages? What kind of response time do you need? How often are you doing updates? What kind of data rate are you expecting? What are you trying to control? Information like that is needed.

I doubt ser2net is going to be your ultimate solution, so you are probably better off starting a new thread explaining just what you are trying to do.

czhowl

Save telnet console output into file:


Code: [Select]
mv /usr/bin/tee /usr/bin/tee.bk
opkg update
opkg  install coreutils-tee


Code: [Select]
telnet localhost 6001 | tee -a yun.txt

Save file into RAM disk for high speed:

Code: [Select]
telnet localhost 6001 | tee -a /tmp/yun.txt





Hi,

Is there any way to run
Code: [Select]
telnet localhost 6001 | tee -a yun.txt at linux startup and keep running?

I tried to put it in /etc/rc.local but it seems not working.

Thanks

ShapeShifter

An old topic, but I want to thank sonnyyu for this thread, it really helped me out. I have a work project, where the debug console is a TTL level serial port. I normally use a little TTL to RS-232 adapter to talk to it, but I have a temporary need to access it remotely over the network. There are two of these devices, and being a short-term need, I didn't want to spend a lot of time or money on dedicated hardware. I had a couple Yuns available, and my first thought was to use software serial to copy data back and forth to the Console class, and remotely access the console. But then I remembered this thread.

I followed the procedure detailed in the first post of this thread, except when it came to the sketch. I didn't need the sketch to do anything here, so I put in a jumper wire to ground out the reset pin to hold the '32U4 processor in reset. I then hooked up jumper wires from pins D0, D1, and ground to the TTL level console port pins. I can now Telnet into the ser2net port on the Yuns, and remotely access the console of my project. It works well!

It's a bit of overkill, and it is probably the most expensive TTL serial to Ethernet converter, but it is what I had on hand and was very quick and simple to implement. And when this short term need is through, I can once again use the Yuns for other projects.

I was skeptical about ser2net before, but now I have to say thank you to sonnyyu!

Go Up