You can test for the presence of “connection” with this approach:

Copy to Clipboard

 

The code above will use connection.sendMessage() when running on the display module but will use console.log() when running on the PC.