automation-comms

1.0.5 • Public • Published

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 {
  connect,
  controlCurtain,
  controlLight,
  disconnect,
} from 'automation-comms'; 

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, 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,
    })

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.

Readme

Keywords

none

Package Sidebar

Install

npm i automation-comms

Weekly Downloads

45

Version

1.0.5

License

ISC

Unpacked Size

19.5 kB

Total Files

4

Last publish

Collaborators

  • mohammad-el-bachtigui