The React Native UDP Control package provides a convenient interface for controlling lights and curtains via UDP sockets in React Native applications.
To install the package:
npm install automation-comms
yarn add automation-comms
After installing the automation-comms package,
you need to reinstall your application to properly set up the
react-native-udp peer dependency. This ensures all native
dependencies are linked correctly.
Import the package into your React Native code:
import {
connect,
controlCurtain,
controlLight,
disconnect,
} from 'automation-comms';
connect(server_ip, server_port, bindingPort)
Purpose: Establishes a connection to the server through a UDP socket.
- server_ip: The IP address of the host where the UDP socket should send the command.
- server_port: The port of the server.
- bindingPort (optional): The port to bind the socket to. Default value is 5000. Change this if you encounter connection errors.
connect({bindingPort: 5000, serverIP: '192.168.2.187', serverPort: 6000});
Purpose: Disconnects from the server. No parameters.
disconnect();
Purpose: Controls the light (turn on or off) based on the parameters.
- channel: The channel ID.
- action: Either "on" or "off".
- value: Dimming -->The value of the bulb (0-100) if action is "on", or 0 if action is "off". Relay --> The value of the bulb 100 if action is "on", or 0 if action is "off".
- devID: The device ID.
- subId: The subnet ID.
controlLight({
channelid: 333,
value: 10,
action: 'on' or 'off',
DevId: 4,
SubID: 16,
});;
Purpose: Controls the curtain (STOP, CLOSED, or OPEN) based on the parameters.
- channel: The channel ID.
- action: Either "CLOSED" OR "OPEN" OR "STOP".
- devID: The device ID.
- subId: The subnet ID.
controlCurtain({
channelid: 31,
action: "CLOSED" OR "OPEN" OR "STOP",
DevId: 12,
SubID: 21,
})
- Make sure to call connect() before using controlLight() or controlCurtain().
- Ensure that the server is configured to receive UDP packets on the specified IP address and port.