1.0.4 • Published 1 year ago
react-native-automationcomms v1.0.4
Introduction
The React Native UDP Control package provides a convenient interface for controlling lights and curtains via UDP sockets in React Native applications.
Installation
To install the package, use npm:
npm install react-native-automationcomms
Usage
Import the package into your React Native code:
import import {
connect,
controlCurtain,
controlLight,
disconnect,
sendMessage,
} from 'react-native-automationcomms';
Functions
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});
disconnect()
Purpose: Disconnects from the server. No parameters.
disconnect();
controlLight(channel, value, action, devID, subId)
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,
});;
controlCurtain(channel, action, devID, subId)
Purpose: Controls the curtain (stop, close, or open) based on the parameters.
- channel: The channel ID.
- action: Either "close", "stop", or "open".
- devID: The device ID.
- subId: The subnet ID.
controlCurtain({
channelid: 31,
action: 'CLOSED',
DevId: 12,
SubID: 21,
})
Notes
- 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.