1

Topic: set a time to disconnect connection between smartphone and esp8266

considering that remotexy did not support to connect more than one phone at same time so i'd like to make a timer to disconnect the connection between phone and esp8266 so, if the application has been held in background , it will not effect the efficency of our device and the phone will be disconnected and give a chance to another phone to connect again

also , if it is possible to make it if device connected and another one try to connect disconnect the first connection and esablish another one

so please help me to make this idea come into reality

2

Re: set a time to disconnect connection between smartphone and esp8266

Welcome

There is no proper way to do that

When a Control (Buttons, Sliders etc) value has changed, assign millis() to a variable, and periodically check if ( RemoteXY.connect_flag == 1 && millis() - variable >= e.g. 30 seconds ), if true then stop calling RemoteXY_Handler() for like 10 seconds, this will kick the currently connected client and allow a new connection

It's possible to do something more elegant, but requires to write a custom remotexy library

3

Re: set a time to disconnect connection between smartphone and esp8266

First of all thanks for your fast response
Actually I'd like to know how can I stop remotexy handler , another thing can I edit remotexy library in order to detect if another device try to connect and there is device already connected , to disconnect the first connection and establish another one

4

Re: set a time to disconnect connection between smartphone and esp8266

As far as I know, it's not possible to detect when a device try to connect.

To stop remotexy handler, just stop calling RemoteXY_Handler() from loop(), using delay() (noob's way), or using millis() like in the Blink Without Delay example from Arduino IDE.

Note that you can possibly create more than one RemoteXY interface in the same program. So multiple users could connect to these multiples interfaces. You can use the same RemoteXY_CONF array for all interfaces but the RemoteXY struct must be unique to each interface.

http://forum.remotexy.com/viewtopic.php?id=15

5

Re: set a time to disconnect connection between smartphone and esp8266

Thanks for your continuous help, could you please give an example to stop remotexy handler using millis

6

Re: set a time to disconnect connection between smartphone and esp8266

Something like this

void loop()
{
  bool stopRemoteXYFor10Seconds = false; // set this variable to true whenever you need to stop remotexy for 10 seconds.

  uint32_t now = millis();
  static bool stopRemoteXY = false;
  static uint32_t stopRemoteXYMillis = now;

  if ( !stopRemoteXY && stopRemoteXYFor10Seconds )
  {
    stopRemoteXY = true;
    stopRemoteXYMillis = now;
  }

  if ( stopRemoteXY && now - stopRemoteXYMillis >= 10000UL )
  {
    stopRemoteXY = false;
  }

  if ( !stopRemoteXY )
  {
    RemoteXY_Handler ();
  }
}

7

Re: set a time to disconnect connection between smartphone and esp8266

i have used your example to make if phone connected wait 5 seconds then stop app for 10 seconds and it doesnt work properly so could you help me to figure out the issue and help me to make this code run as i plan to

unsigned long ledStarted = 0;
const long interval = 5000;

void loop()
{
bool stopRemoteXYFor10Seconds = false; // set this variable to true whenever you need to stop remotexy for 10 seconds.

  uint32_t now = millis();
  static bool stopRemoteXY = false;
  static uint32_t stopRemoteXYMillis = now;

  if ( !stopRemoteXY && stopRemoteXYFor10Seconds )
  {
    stopRemoteXY = true;
    stopRemoteXYMillis = now;
  }

  if ( stopRemoteXY && now - stopRemoteXYMillis >= 10000UL )
  {
    stopRemoteXY = false;
  }

  if ( !stopRemoteXY )
  {
     remotexy.handler();
  }
   unsigned long currentMillis = millis();
  if (currentMillis - ledStarted >= interval && remotexyStruct.connect_flag!=0 ) {
    ledStarted = currentMillis;
stopRemoteXYFor10Seconds = true;
  }
}

8

Re: set a time to disconnect connection between smartphone and esp8266

Dear Guillaume
Could you please provide another try to help