An archive of community.esquilo.io as of Saturday January 26, 2019.

Can Esquilo survive on delay(0) alone?

steveb48

Hi All,

I'm working on my second project. This is similar to the first ( Web interface into RS485 device) but the serial timing is much tighter. The bus is running at 38400 baud and there are few gaps. You need to stay in sync with everything so you know when it's your turn to talk. Miss your turn and you get skipped in less than 1ms.

If I use anything larger than a delay(0) in my loop, I drop characters.

I'm seeing a problem on the web side where the erpc requests are failing due to the connection dropping.

Could the delay(0) be the problem? It doesn't seem to be the network as my other device is 2' away and the web logs are clean.

thanks
Steve

Scott_Shumate

Hi Steve,

Running delay(0) should allow you to process incoming ERPC calls without dropping. For example, if I run the following nut:

function hello() {
return "hello";
}

while (true) {
delay(0);
}

I can do ERPC calls to hello() continuously without dropping. The only time this is not the case is if you raise the Squirrel VM priority with the priority() function. With elevated priority, you can certainly starve out the ERPC calls (and the IDE too!).

When you say the connection is dropping, is the network LED going off or is it just that ERPC calls are timing out?

-Scott

steveb48

Hi Scott,

I believe the LED is remaining lit as I still have a connection with the IDE. It seems to be the ERPC calls are timing out with a connection dropped message.

Looks like that's a different problem.

On a related note, if I do

and there is no data available to read, do you allow ERPCs to run or should I do something like

while(serial.available() < 3)
delay(0)

that checks to see if data is available before the read to allow another delay(0) call?

thanks
Steve

Scott_Shumate

You'll definitely want to do the later. Most of the Squirrel classes will block if you read more than is available. This will block the Squirrel VM thread and make it stop responding to your ERPC calls.

steveb48

The blocking read calls were getting me. Works great now.

Thanks Scott!

Steve

steveb48

Hi Scott,

When I run my Nut, the Equilio goes offline in Nest. If I simplify my program such that it's not doing any IO and the while loop contains only a delay(0), the same thing happens.

Do you see the same thing with your example code? It's takes a minute or so for it to happen. If I kill the Nut, it come back online in about 10 seconds.

Any ideas?
thanks
Steve

patrick

Hi Steve,

I have a couple of systems running most of the time and they both show as "online" in the Nest manager page. Are you accessing the IDE locally or through the cloud proxy?

Would you try this simple code and see if the same happens, please?

count <- 0;
while (true) {
print(count + "\n");
count++;
delay(1000);
}
steveb48

Hi Patrick,

I can give that code a go when I get home but I expect that it will work just fine.

I have 2 systems. One has delays with a non zero value. I've forgotten what it was. 10 maybe? It works great. It's doing a very similar task as my problem child. Controlling something via a RS485. In this case a Pentair pool controller. The protocol is pretty simple and their are big gaps (2.5 seconds) where nothing is sent. Lots of delays()s.

My new system is controlling a Crestron Adagio. That one runs at 38.4kb and the largest gap in data is 2.8ms. On this system I have to use delay(0)s. I do spin on serial.available() with a delay(0) so I'm not blocking on reads.

If I take all the IO out of my code such that the main while loop is just a delay(0), the device goes offline on nest. If I kill the nut, it comes back. The status polling code in javascript is running every 2 seconds and returns the contents of 12 variables. No serial IO. I haven't tried closing the browser to shutdown the polling to see if that makes a difference.

In both cases I'm using the IDE locally.

Thanks,
Steve

steveb48

Hi Patrick,

Your code runs just fine. Running Scott's code listed above causes Nest to show offline in about 2 minutes. I tried both twice. Scott's code died at 1:54 and 2:02 and your code ran over 7 minutes both times.

I should point out that running Scott's code I was not calling hello() via erpc. It was just the nut running.