Home > other >  How to identify a mobile app user when connecting to Wi-Fi?
How to identify a mobile app user when connecting to Wi-Fi?

Time:10-18

There is a home automation built with Tuya Smart IoT platform. It is used for guest house and has some scenarios, like welcoming guests, opening doors, powering on the light, etc.

Visitors book this house via mobile app (built with React Native). Is there a possibility to identify user in mobile app, so that when he connects to Wi-Fi router, some scenario is triggered?

Tuya IoT is able to run scenarios when new device is connected, but how to determine whether connected device is exactly the same that booked this house from app? It’s not possible to read device’s IMEI or MAC-address, so have no idea how to implement this identification.

CodePudding user response:

you can use react-native-net-info library, with this we can get the state of connection like wifi or sim network etc. Also we can get the device IPAddress and various other information related to connection.

Also detailed properties are mentioned in the NPM link given below.

link : https://www.npmjs.com/package/@react-native-community/netinfo

CodePudding user response:

npm i react-native-network-info

import { NetworkInfo } from "react-native-network-info";



// Get Local IP
NetworkInfo.getIPAddress().then(ipAddress => {
  console.log(ipAddress);
});
 
// Get IPv4 IP (priority: WiFi first, cellular second)
NetworkInfo.getIPV4Address().then(ipv4Address => {
  console.log(ipv4Address);
});
 

// Get Broadcast
NetworkInfo.getBroadcast().then(broadcast => {
  console.log(broadcast);
});
 

// Get SSID
NetworkInfo.getSSID().then(ssid => {
  console.log(ssid);
});



// Get BSSID
NetworkInfo.getBSSID().then(bssid => {
  console.log(bssid);
});



// Get Subnet
NetworkInfo.getSubnet().then(subnet => {
  console.log(subnet);
});
 

// Get Default Gateway IP
NetworkInfo.getGatewayIPAddress().then(defaultGateway => {
  console.log(defaultGateway);
});



// Get frequency (supported only for Android)
NetworkInfo.getFrequency().then(frequency => {
  console.log(frequency);
});
  • Related