This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
docs:blox:blox-wifi-messages [2024/08/28 13:45] admin |
docs:blox:blox-wifi-messages [2024/08/28 17:26] (current) admin |
||
|---|---|---|---|
| Line 3: | Line 3: | ||
| Broadcasting and Receiving messages over WIFI allows you to link multiple BLOX devices together across your local WIFI network. It can also be used to interact with external applications | Broadcasting and Receiving messages over WIFI allows you to link multiple BLOX devices together across your local WIFI network. It can also be used to interact with external applications | ||
| - | ==== BLOX UDP Communication System Overview ==== | + | ===== 6.6.3.1 |
| - | **Message Sending and Receiving**: | + | ===== Message Sending and Receiving : ===== |
| - | BLOX devices communicate using UDP to send (broadcast) and receive messages. Each message includes a sensor value (analog or digital) and a unique | + | BLOX devices communicate using [[https:// |
| - | **TagID-Based Processing**: | + | **ID Tag****-Based Processing**: |
| - | * **Sending**: | + | * **Sending**: |
| - | * **Receiving**: | + | * **Receiving**: |
| - | * **BLOX2 Example**: If BLOX 2 is set up with an IF block to look for a message with a certain | + | * **BLOX2 Example**: If BLOX 2 is set up with an IF block to look for a message with a certain |
| - | * **BLOX3 Example**: If BLOX 3 is not set up to listen for that TagID, it will ignore the message. | + | * **BLOX3 Example**: If BLOX 3 is not set up to listen for that ID Tag, it will ignore the message. |
| **Multiple Listeners**: | **Multiple Listeners**: | ||
| - | Multiple BLOX devices can be configured to respond to the same TagID, allowing for coordinated actions across devices. | + | Multiple BLOX devices can be configured to respond to the same ID Tag, allowing for coordinated actions across devices. |
| **Cross-Platform Compatibility**: | **Cross-Platform Compatibility**: | ||
| Line 25: | Line 25: | ||
| 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. | ||
| - | ===== 6.6.3.1 Sending Messages ===== | + | ===== 6.6.3.2 Sending Messages ===== |
| + | |||
| + | You can send analog or digital sensor values | ||
| + | |||
| + | Note the matching ID Tags (compared to receiving section below) to identify the outgoing messages | ||
| + | |||
| + | ^Sending an analog sensor value^Sending a digital sensor value| | ||
| + | |{{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 6.6.3.3 Receiving Messages ===== | ||
| + | |||
| + | Received messages are available as " | ||
| + | |||
| + | Note the matching ID Tags (compared to sending section above) to identify the incoming messages | ||
| + | |||
| + | ^Receiving analog sensor value^Receiving digital sensor value| | ||
| + | |{{docs: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 6.6.3.4 Monitoring / troubleshooting messages ===== | ||
| + | |||
| + | You can see broadcast messages in the BLOX Serial/USB logs | ||
| + | |||
| + | {{: | ||
| + | |||
| + | 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 / send messages from a computer to help you troubleshoot | ||
| + | |||
| + | {{: | ||
| + | |||
| + | ---- | ||
| + | |||
| + | ===== 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 | ||
| + | < | ||
| + | |||
| + | const dgram = require(' | ||
| + | |||
| + | // Create a UDP socket | ||
| + | const client = dgram.createSocket(' | ||
| + | |||
| + | // Enable broadcast on the socket | ||
| + | client.on(' | ||
| + | client.setBroadcast(true); | ||
| + | }); | ||
| + | |||
| + | // The message to send | ||
| + | const message = Buffer.from(' | ||
| + | |||
| + | // The target port and broadcast address | ||
| + | const PORT = 49160; | ||
| + | const BROADCAST_ADDR = ' | ||
| + | |||
| + | // Send the message | ||
| + | client.send(message, | ||
| + | if (err) { | ||
| + | console.error(`Error sending message: ${err}`); | ||
| + | } else { | ||
| + | console.log(' | ||
| + | } | ||
| + | client.close(); | ||
| + | }); | ||
| + | |||
| + | </ | ||
| + | |||
| + | For example: Receiving via a custom nodejs program | ||
| + | |||
| + | < | ||
| + | const dgram = require(' | ||
| + | |||
| + | // Create a UDP socket for the server | ||
| + | const server = dgram.createSocket(' | ||
| + | |||
| + | // Define the port to listen on | ||
| + | const PORT = 49160; | ||
| + | |||
| + | // Event listener for when the server receives a message | ||
| + | server.on(' | ||
| + | const message = msg.toString(); | ||
| + | const keyValue = message.split(' | ||
| + | |||
| + | // Check if the message is in the expected format | ||
| + | if (keyValue.length === 2 && keyValue[0] === ' | ||
| + | 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(' | ||
| + | const address = server.address(); | ||
| + | console.log(`Server listening on ${address.address}: | ||
| + | }); | ||
| + | |||
| + | // Bind the server to the port | ||
| + | server.bind(PORT); | ||
| + | |||
| + | </ | ||
| - | ===== 6.6.3.2 Receiving Messages ===== | ||