npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

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()