automation-comms
v1.1.7
Published
this package is for automation comms
Downloads
76
Readme
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:
For NPM
npm install automation-comms
For YARN
yarn add automation-comms
Important:
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.
Usage
Import the package into your React Native code:
import {
setConfigurations
connect_UDP,
disconnect_UDP,
connect_MQTT,
disconnect_MQTT,
changeMode,
controlLight,
controlFan,
controlCurtain,
ControlUniversalSwitch,
ControlHardwareScene,
ControlAc,
GetLightORFanStatus,
GetUniversalSwitchStatus,
GetHardwareSceneStatus,
GetSensorStatus,
GetAcStatus,
startListner,
stopListner
} from 'automation-comms';
Functions
setConfigurations
Purpose: This function sets the configurations for the connections. It is compulsory to call setConfigurations before invoking any other function such as connectMQTT or connectUDP. This function will gather the necessary information for UDP and MQTT connections from the user and save it to local storage.
- udpIpAddress: The IP address for the UDP connection.
- udpPort: The port number for the UDP connection.
- bindingPort(optional): The binding port number for the UDP binding(default it be 5000)
- mqttServer (optional): The URL of the MQTT server.
- mqttPort (optional): The port number for the MQTT server.
- mqttPublisherTopic (optional): The topic to which the MQTT publisher will send messages.
- mqttSubscriberTopic (optional): The topic to which the MQTT subscriber will listen.
- user (optional): Specifies the username for authenticating with the MQTT broker.
- pass (optional): Specifies the password for authenticating with the MQTT broker.
setConfigurations({
udpIpAddress: '192.168.1.177',
udpPort: 5000,
bindingPort: 6000,
mqttServer: 'mqtt://a15657c5.ala.dedicated.aws.emqxcloud.com:1883',
user: 'user-name',
pass: 'user-password',
mqttPublisherTopic: 'mqtt-Publisher-Topic',
mqttSubscriberTopic: 'mqtt-Subscriber-Topic',
});
UDP connection
Purpose: Establishes a connection to the server through a UDP socket. We need to set values in setConfigurations function
- udpIpAddress: The IP address of the host where the UDP socket should send the command.
- udpPort: 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_UDP();
disconnect UDP
Purpose: Disconnect UDP connection from the server. No parameters.
disconnect_UDP;
MQTT connection
Purpose: Establishes a connection to the server through a MQTT socket. We need to set values in setConfigurations function for MQTT connection
- mqttServer: Specifies the MQTT server URL. This can be an IP address or a domain name where the MQTT broker is hosted.
- user: Specifies the username for authenticating with the MQTT broker.
- pass: Specifies the password for authenticating with the MQTT broker.
- mqttPublisherTopic: Defines the publisher's identifier used for publishing messages to the MQTT broker.
- mqttSubscriberTopic: Specifies the topic to which the MQTT subscriber will listen. The subscriber will receive messages from this topic.
connect_MQTT();
disconnect MQTT
Purpose: Disconnect MQTT connection from the server. No parameters.
disconnect_MQTT;
Change Mode
Purpose:Changes the mode of communication between UDP and MQTT. The user switches from UDP to MQTT, the method checks for saved MQTT credentials and establishes the MQTT connection, disconnecting the UDP connection. Similarly, if the user switches from MQTT to UDP, the method ensures the UDP connection is established and MQTT is disconnected. If the required credentials are not set, an exception is thrown.
Parameter
- mode (required): Specifies the mode of communication. Acceptable values are "local" (for UDP) or "mqtt" (for MQTT). This parameter is required and cannot be null.
changeMode('mqtt/local');
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,
});
controlFan(channelid, value, action, devId, subID)
Purpose: Controls the Fan based on the parameters.
- channelid: The channel ID.
- value: between 0 TO 8.
- action: "on" OR "off",
- devId: The device ID.
- subID: The subnet ID.
controlFan({
channelid: 1,
value: 0,
action: 'off',
devId: 43,
subID: 1,
})
controlCurtain(channel, action, devID, subId)
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,
})
ControlUniversalSwitch(channelid, action, devId, subID)
Purpose: Controls the UniversalSwitchs (on, or off) based on the parameters.
- channel: The channel ID.
- action: Either "on" OR "off".
- devId: The device ID.
- subID: The subnet ID.
ControlUniversalSwitch({
channelid: 31,
action: "on" OR "off",
devId: 12,
subID: 21,
})
ControlHardwareScene(devId, subID, scene, zone)
Purpose: Controls the ControlHardwareScene based on the parameters.
- devId: The device ID.
- subID: The subnet ID.
- scene: The scene ID.
- zone: The zone ID.
ControlHardwareScene({
scene: 2,
zone: 1,
devId: 12,
subID: 21,
})
ControlAc(acType, deviceID, subnetID, acSlot, action,acMode,fanSpeed,coolingTemp,heatingTemp,autoTemp,dryTemp)
Purpose: Controls the Ac based on the parameters.
- acType: "hvac" OR "enviro".
- deviceID: The device ID.
- subnetID: The subnet ID.
- acSlot: The AC Slot ID(AcSlot only required if acType is Enviro).
- action: "on" OR "off",
- acMode: The AC Mode.
- fanSpeed: The Fan Speed.
- coolingTemp: The Cooling Temp.
- heatingTemp:The Heating Temp,
- autoTemp: The Auto Temp.
- dryTemp: The Dry Temp. Note: if the acMode is set to cooling then set cooling temperature, and if acMode is heat then set heating temperature.
ControlAc({
acType: 'hvac',
deviceID: 220,
subnetID: 2,
acSlot: 2,
action: 'on',
acMode: 3,
autoTemp: 15,
fanSpeed: 0,
})
Get Devices Current Status
Get Light/Fan Status
Purpose: Retrieves the status of a lights or fans based on the parameters. Parameters:
- deviceID (devId): The ID of the device.
- subnetID (subID): The ID of the subnet.
GetLightORFanStatus({
devId: 43,
subID: 1,
});
Get Universal Switch Status
Purpose: Retrieves the status of a universal switch based on the parameters.
Parameters:
- deviceID (devId): The ID of the device.
- subnetID (subID): The ID of the subnet.
- channelid (channelid): The channel ID of the universal switch.
GetUniversalSwitchStatus({
channelid: 5,
devId: 5,
subID: 1,
});
Get Hardware Scene Status
Purpose: Retrieves the status of a hardware scene based on the parameters.
Parameters:
- deviceID (devId): The ID of the device.
- subnetID (subID): The ID of the subnet.
- zoneID (zone): The ID of the zone.
GetHardwareSceneStatus({
devId: 44,
subID: 1,
zone: 1,
});
Get Sensor Status
Purpose: Retrieves the status of a sensor based on the parameters.
Parameters:
- deviceID (devId): The ID of the device.
- subnetID (subID): The ID of the subnet.
GetSensorStatus({
devId: 43,
subID: 1,
})
Get AC Status
Purpose: Retrieves the status of an AC unit based on the parameters.
Parameters:
- deviceID (devId): The ID of the device.
- subnetID (subID): The ID of the subnet.
- acType: 'enviro' or 'hvac' , by default it will be hvac
- acSlot: required only if acType is "enviro"
GetAcStatus({
deviceID: 12,
subnetID: 1,
acSlot: 1,
});
startListner()
Purpose: Returns the event of the device's status changes.
- If UDP is connected, starts the UDP listener.
- If MQTT is connected, subscribes to subScriberTopic.
- If both are not connected, throws an exception.
startListner(value => {
console.log('listnerCallback: ', value);
});
stopListner()
Purposer: Stop the event of the device's status changes.
stopListner()