Rest api : YunServer 146 Connection refused

after w while of experimenting i found a big problem witch my Yun.

I'm using Rest api and program works fine but after a while i get:
"Could not connect to YunServer 146 Connection refused" error
And i can't make no more requests! ONLY REBOOT FIX THIS:(

how can i diagnose this problem?

using OpenWrt-Yun 1.4.1
REST API access set to Open.

YunServer server;
(...)
  server.noListenOnLocalhost();
  server.begin();
(...)
void loop() {
 
  YunClient client = server.accept();

  if (client) 
  {
    client.setTimeout(5);
    
    process(client);

    client.stop();
  }

   delay(50);
}

localhost fails itself to:(
/usr/bin/curl http://localhost/arduino/aa

Could not connect to YunServer 146

  1. Yun configuration page, make sure REST API access set Open.

Please post the whole sketch: devil is in the details

Is there anycontrol on REST api in SSH?

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>

// Listen on default port 5555, the webserver on the Yún
// will forward there all the HTTP requests for us.
YunServer server;

void setup()
{
  // Bridge startup
  for(int i=2;i<=13;i++)
  pinMode(i, OUTPUT);
  
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);
  pinMode(A4, OUTPUT);
  pinMode(A5, OUTPUT);
  
  digitalWrite(13, LOW);
  Bridge.begin();
  digitalWrite(13, HIGH);

  server.listenOnLocalhost();
  server.begin();
}

void loop() {
  // Get clients coming from server
  YunClient client = server.accept();

  // There is a new client?
  if (client) 
  {
    client.setTimeout(5);
    
    // Process request
    process(client);

    // Close connection and free resources.
    client.stop();
  }

   delay(50); // Poll every 50ms
}

void process(YunClient client) 
{
  // read the command
  String command = client.readStringUntil('/');

  // is "digital" command?
  if (command == "digital") 
  {
    digitalCommand(client);
    return;
  }
}

void digitalCommand(YunClient client) 
{
  int value;

  // Read pin number
  int pin = client.parseInt();

  // If the next character is a '/' it means we have an URL
  // with a value like: "/digital/13/1"
  if (client.read() == '/')
  {
    value = client.parseInt();
    digitalWrite(pin, value);
  }
  else
  {
    value = digitalRead(pin);
  }

  // Send feedback to client
  client.print(F("Pin D"));
  client.print(pin);
  client.print(F(" set to "));
  client.println(value);
}

Two ways;-

A.

uci show arduino
...
arduino.@arduino[0].secure_rest_api=true
...
uci  set arduino.@arduino[0].secure_rest_api=false
uci commit arduino
uci show arduino
...
arduino.@arduino[0].secure_rest_api=false
...

B.

nano /etc/config/arduino
config arduino
        option password '775e9f944188a7bcb36e9ca5dc51672b44bcceeb7d56d89dfb914e
        option secure_rest_api 'false'
...
uci commit arduino

or

reboot Yun

It looks like the python side of the Bridge is dying. Is there some memory hungry process that's running? Kernel may decide to kill processes at random when going out of memory

How can an I see/edit “python side of the Bridge” ?

Have you installed additional packages? Do you reckon one of them is eating all the RAM?

Also: does stock Bridge example work fine?

i have
installed nano and samba server.
I updated the openwrt, changed charger, reupladed the sketch: problem gone.
I still don’t know what was going on. Guess I will never know.