Dinner is ready!

Dinner is ready!

At Yoctopuce, some of our developers have teenagers who love video games. At mealtimes, it's sometimes very often difficult to unhook them from their computers, especially when they're playing with headphones. This week, we're going to try and solve this problem the Yoctopuce way.





The plan is to discreetly install a small service on the children's computers to broadcast a message on the audio output when a remote switch is pressed. When dinner is ready, simply press the switch in the kitchen and all the computers in the house broadcast a message announcing that it's dinnertime. This way, even if the teenager uses headphones, they will hear the announcement, and parents won't have to shout across the house.

To do this, we need an "emergency stop" button that we'll connect to a Yocto-Knob (or any other Yoctopuce module with an anButton input). This Yocto-Knob is connected to a YoctoHub-Wireless-n to make it accessible to all local network machines.

System diagram
System diagram



All this is discreetly integrated into the kitchen cabinet.

The integrated knob in the kitchen
The integrated knob in the kitchen



Once the button has been installed, all that's left to do is set up the Windows service to be installed on the machines.

The Windows service

The service is quite simple. On startup, it configures the Yoctopuce library to establish a connection with the YoctoHub-Wireless-n, and retrieves the YAnButton object that interacts with the input of the Yocto-Knob to which the button is connected. It configures the voice synthesizer and a timer calls the CheckButton method every 5 seconds.

...
// Registers the connection to the YoctoHub
string errmsg = "";
if (YAPI.PreregisterHub(_url, ref errmsg) != YAPI.SUCCESS) {
  FatalError("YAPI.PreregisterHub failed:" + errmsg);
}
// Instantiates an YAnButton object to interact with button
_button = YAnButton.FindAnButton(_hwid);
 // Configures Text2Speech
 _synth = new SpeechSynthesizer();
// Creates a timer that calls CheckButton every 5 seconds
_timer = new Timer(CheckButton, null, TimeSpan.Zero, TimeSpan.FromSeconds(5));
...



If you're familiar with our library, you'll see there's nothing really special about it other than the use of the YAPI.PreregisterHub method, which doesn't return an error when the YoctoHub-Wireless-n can't be reached. For more details on this method, see our post "RegisterHub() vs. PreregisterHub()".

The CheckButton method is also very simple. It checks that the button is online using the isOnline() method. If it is, it tests the button's state with the get_isPressed() method and reads the message using the Windows voice synthesizer according to the state of the button.

private void CheckButton(object state)
{
  if (_button.isOnline()) {
    if (_button.get_isPressed() == YAnButton.ISPRESSED_TRUE) {
      _synth.Speak(_message);
    }
  } else {
    EventLog.WriteEntry("CheckButtonService", "Button is offline",
                        EventLogEntryType.Error);
  }
}



As you can see, the code for interacting with the Yocto-Knob is very simple. The first reason is that the Yoctopuce library hides all the complexity of the connection between the Yoctopuce modules and the application. The other reason is that we're using an emergency stop button. As this button remains activated, there's no need to be super-reactive and register a callback to immediately capture the transition.

The complete project is available on GitHub. The repository contains all the source code for the service, plus a compiled version that can be used directly in the bin/Release subdirectory.


Testing and installing the service

Now that we've got a working service, all that's left to do is to test it and to install it on the computers. The first step is to copy the entire bin/Release directory onto the computer, ideally into a hidden directory so that it cannot be detected too easily.

Then, you must open a terminal with administrator rights and launch the YoctoStopTheGamer.exe application with the --test option followed by the IP address of the YoctoHub-Wireless-n. You'll also need to pass the HardwareID or logical name of the input to which you've connected your emergency stop button. If you're not familiar with the concepts of HardwareID and logical name, you can read our post on the logical structure of Yoctopuce modules, which explains in detail how our modules work. By default, the application reads a "Stop playing" message, but this can be changed with the --msg option.

The following example reads the message "Dinner is ready!" when the anButton1 input of Yocto-Knob YBUTTON1-2F471 is activated.

C:\hidden>.\YoctoStopTheGamer.exe --test 192.168.2.49 YBUTTON1-2F471.anButton1 --msg "Dinner is ready!" Yoctopuce Lib version is :2.0.62875 (2.0.62875) Hub URL :localhost Button :input1 Message :Dinner is ready! Local : Selected voice:Microsoft Hazel Desktop (lang=en-GB)



When these parameters have been validated, simply replace the --test option with --install to install and start the service.

C:\hidden>.\YoctoStopTheGamer.exe --install 192.168.2.49 YBUTTON1-2F471.anButton1 --msg "Dinner is ready!" C:\hidden>



When the service has been installed, it is automatically started at each boot without any visible window. To avoid arousing suspicion, the service is listed as "Gamer Compliance Service" in the list of services.

The service is named Gamer Compliance Service
The service is named Gamer Compliance Service



Note that the application also allows you to uninstall the service using the --uninstalloption.


Conclusion

Thanks to Gamer Compliance Service, video game addicted teens will no longer have an excuse to miss a meal... At least until they come across this post :-)

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.