docs:blox:blox-wifi-messages

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
docs:blox:blox-wifi-messages [2024/08/28 17:12]
admin
docs:blox:blox-wifi-messages [2024/08/28 17:26] (current)
admin
Line 24: Line 24:
  
 This setup provides a flexible and extensible way to manage inter-device communication and integration with other networked applications. This setup provides a flexible and extensible way to manage inter-device communication and integration with other networked applications.
- 
-**Technical Details**: 
- 
-BLOX sends and receives on port 49160 
  
 ===== 6.6.3.2 Sending Messages ===== ===== 6.6.3.2 Sending Messages =====
Line 36: Line 32:
  
 ^Sending an analog sensor value^Sending a digital sensor value| ^Sending an analog sensor value^Sending a digital sensor value|
-|{{:docs:blox:pasted:20240828-170512.png}}|{{:docs:blox:pasted:20240828-170512.png}}|+|{{:docs:blox:pasted:20240828-170512.png}}|{{:docs:blox:pasted:20240828-172440.png}}|
  
 ---- ----
Line 47: Line 43:
  
 ^Receiving analog sensor value^Receiving digital sensor value| ^Receiving analog sensor value^Receiving digital sensor value|
-|{{:docs:blox:pasted:20240828-170512.png}}|{{:docs:blox:pasted:20240828-170512.png}}|+|{{docs:blox:pasted:20240828-172622.png}}|{{:docs:blox:pasted:20240828-172524.png}}|
  
 ---- ----
  
-===== 6.6.3.4 Monitoring messages =====+===== 6.6.3.4 Monitoring / troubleshooting messages ===== 
 + 
 +You can see broadcast messages in the BLOX Serial/USB logs 
 + 
 +{{:docs:blox:pasted:20240828-171736.png}}
  
 Messages are broadcast unencrypted for simplicity. This also allows you to very easily monitor and troubleshoot issues, as well as integrate it into other scripts and programs Messages are broadcast unencrypted for simplicity. This also allows you to very easily monitor and troubleshoot issues, as well as integrate it into other scripts and programs
  
-For example you can listen out for messages from a computer to help you troubleshoot+For example you can listen out for messages / send messages from a computer to help you troubleshoot 
 + 
 +{{:docs:blox:pasted:20240828-171245.png}} 
 + 
 +---- 
 + 
 +===== 6.6.3.4 3rd party integration ===== 
 + 
 +You can use your own code to send and receive UDP messages in the format of idtagstring=value on port 49160 
 + 
 +**Technical Details**: 
 + 
 +BLOX sends and receives on port 49160 
 + 
 +Data is sent as a simple string in the format idtag=value. For analog sensors the value is the numeric value. For digital sensors its 0/1 respectively. Quite simple and easy 
 + 
 +For example: Sending via a custom nodejs program 
 +<code> 
 + 
 +const dgram = require('dgram'); 
 + 
 +// Create a UDP socket 
 +const client = dgram.createSocket('udp4'); 
 + 
 +// Enable broadcast on the socket 
 +client.on('listening', function() { 
 +  client.setBroadcast(true); 
 +}); 
 + 
 +// The message to send 
 +const message = Buffer.from('analog_read_1_blox_2=115'); // construct value dynamically in your own code 
 + 
 +// The target port and broadcast address 
 +const PORT = 49160; 
 +const BROADCAST_ADDR = '255.255.255.255'; 
 + 
 +// Send the message 
 +client.send(message, 0, message.length, PORT, BROADCAST_ADDR, (err) => { 
 +  if (err) { 
 +    console.error(`Error sending message: ${err}`); 
 +  } else { 
 +    console.log('Message broadcasted successfully'); 
 +  } 
 +  client.close(); 
 +}); 
 + 
 +</code> 
 + 
 +For example: Receiving via a custom nodejs program 
 + 
 +<code> 
 +const dgram = require('dgram'); 
 + 
 +// Create a UDP socket for the server 
 +const server = dgram.createSocket('udp4'); 
 + 
 +// Define the port to listen on 
 +const PORT = 49160; 
 + 
 +// Event listener for when the server receives a message 
 +server.on('message', (msg, rinfo) => { 
 +  const message = msg.toString(); 
 +  const keyValue = message.split('='); 
 + 
 +  // Check if the message is in the expected format 
 +  if (keyValue.length === 2 && keyValue[0] === 'analog_read_1_blox_2') { 
 +    const value = keyValue[1]; 
 +    console.log(`Received analog_read_1_blox_2 value: ${value}`); 
 +    // do something with the value 
 +  } 
 +}); 
 + 
 +// Event listener for when the server starts listening 
 +server.on('listening', () => { 
 +  const address = server.address(); 
 +  console.log(`Server listening on ${address.address}:${address.port}`); 
 +}); 
 + 
 +// Bind the server to the port 
 +server.bind(PORT);
  
-{{docs:blox:pasted:20240828-171245.png}}+</code>
  
-You can also see broadcast messages in the BLOX log 
  
-{{docs:blox:pasted:20240828-171245.png}} 
  
  
docs/blox/blox-wifi-messages.1724865165.txt.gz · Last modified: 2024/08/28 17:12 by admin