Git Product home page Git Product logo

rn-native-mqtt's People

Contributors

256hz avatar davesters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rn-native-mqtt's Issues

rn-natinve-mqtt in Expo

Hello!

I have tried using the module while using react-native-cli. After some time I managed to get it to work. I have however now tried to use it using Expo, and I keep getting the same error:
159288707_4359902857357359_1306682232082495332_n
159111102_830239467529853_2073563605472444013_n (1)
159238157_215948980282503_9178310791409286977_n

I have the following code:
import React, {useEffect, useState} from 'react'
import { View, Button, Text} from 'react-native';
import * as Mqtt from 'react-native-native-mqtt';
import buffer from 'buffer'
global.Buffer = buffer.Buffer;

const Mqtt = ({client}) => {
const [error, setError] = useState('');
const [payload, setPayload] = useState('');
const [connectStatus, setConnectStatus] = useState('Disconnected');

const mqttConnect = () => {
    setConnectStatus("connecting");expo
    client.connect({
        clientId: "client",
        username: "crel",
        password: "pass",
        cleanSession: true,
        
    }, err => {setError(err)});
};

const mqttDisconnect = () => {
    setConnectStatus("disconnecting");
    client.disconnect();
};

useEffect(() => {
    if(client != null)
    {
        client.on(Mqtt.Event.Message, (topic, message) => {
            setPayload(message.toString());
        });
        
        client.on(Mqtt.Event.Connect, () => {
            client.subscribe(["robot/+"], [0]);
            setConnectStatus('connected');
        });
        
        client.on(Mqtt.Event.Error, (error) => {
            console.error('error', (error));
            setError(error);
        });
        
        client.on(Mqtt.Event.Disconnect, (cause) => {
            setConnectStatus('Disconnected');
        });
    }
}, [client]);

const publishMessage = (str) => {
    if(client != null && connectStatus == 'connected'){
        const buf = Buffer.from(str);
        client.publish("robot/test", buf, 0, false);
    }
};

return (
    <View>
        <Text>{connectStatus}</Text>
        <Text>error: {error}</Text>
        <Button
            onPress={mqttConnect}
            title = "connect"
        />
        <Button
            onPress={mqttDisconnect}
            title = "disconnect"
        />
        <Button
            onPress={
                publishMessage
            }
            title = "publish test message"
        />
        <Text>{payload}</Text>
    </View>

)

}
export default Mqtt;

Does anyone have a tip, or experienced similar things?

Build error - iOS

Getting this error after adding swift file and adding a bridging header.

Screenshot 2020-06-16 at 12 55 28 PM

My project looks like this -
Screenshot 2020-06-16 at 1 03 11 PM

Content of MQTTBridge.swift
import Foundation

Content of Project-Bridging-Header.h
#ifndef project_Bridging_Header_h #define project_Bridging_Header_h #endif

Pls help

Connect error

Hi, i'm trying to get simple test of this and i'm get error when trying to connect to server, i test my own mqtt server and free public server like mosquitto, but the result its same.

Im testing this on android

I'm start my project with
npx react-native init MqttSample --template react-native-template-typescript

then i'm install the lib with:
npm install react-native-native-mqtt --save

then i run
react-native link react-native-native-mqtt

And my simple code is:

import * as Mqtt from 'react-native-native-mqtt';

const client = new Mqtt.Client('mqtt://test.mosquitto.org:1883');

client.connect(
      {
            clientId: 'miclienteyujuwao',
            cleanSession: true,
            keepAlive: 10,
            timeout: 30000,
            autoReconnect: true,
      },
      err => {
            alert('One error :(');
            console.warn(err); // Error: mqtt://test.mosquitto.org:1883
      },
);

Simply, i'm test with and without typescript templates and the result its same.

System:
    OS: Windows 10 Home, 1909, x64
    CPU: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz
    Memory: 16.0 GB
Packages:
    "react": "16.11.0",
    "react-native": "0.62.1",
    "react-native-native-mqtt": "^0.1.5"

Symbol(s) not found for architecture x86_64

After following steps for adding bridge file and updating minimum deployment to 10.0 for iOS. White trying to run project I am getting following error:

React-native: "0.62.2"

Undefined symbols for architecture x86_64:
  "nominal type descriptor for (extension in Foundation):__C.NSURLSessionWebSocketTask.Message", referenced from:
      _symbolic _____y___________pG s6ResultO So25NSURLSessionWebSocketTaskC10FoundationE7MessageO s5ErrorP in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
      _symbolic _____y___________pGz_Xx s6ResultO So25NSURLSessionWebSocketTaskC10FoundationE7MessageO s5ErrorP in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
  "enum case for (extension in Foundation):__C.NSURLSessionWebSocketTask.Message.data((extension in Foundation):__C.NSURLSessionWebSocketTask.Message.Type) -> (Foundation.Data) -> (extension in Foundation):__C.NSURLSessionWebSocketTask.Message", referenced from:
      react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.write(data: Foundation.Data, handler: (Swift.Error?) -> ()) -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
      closure #1 () -> () in closure #1 (Swift.Result<(extension in Foundation):__C.NSURLSessionWebSocketTask.Message, Swift.Error>) -> () in closure #1 () -> () in react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.scheduleRead() -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
  "enum case for (extension in Foundation):__C.NSURLSessionWebSocketTask.Message.string((extension in Foundation):__C.NSURLSessionWebSocketTask.Message.Type) -> (Swift.String) -> (extension in Foundation):__C.NSURLSessionWebSocketTask.Message", referenced from:
      closure #1 () -> () in closure #1 (Swift.Result<(extension in Foundation):__C.NSURLSessionWebSocketTask.Message, Swift.Error>) -> () in closure #1 () -> () in react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.scheduleRead() -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
  "(extension in Foundation):__C.NSURLSessionWebSocketTask.receive(completionHandler: (Swift.Result<(extension in Foundation):__C.NSURLSessionWebSocketTask.Message, Swift.Error>) -> ()) -> ()", referenced from:
      closure #1 () -> () in react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.scheduleRead() -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
  "type metadata accessor for (extension in Foundation):__C.NSURLSessionWebSocketTask.Message", referenced from:
      react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.write(data: Foundation.Data, handler: (Swift.Error?) -> ()) -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
      closure #1 () -> () in closure #1 (Swift.Result<(extension in Foundation):__C.NSURLSessionWebSocketTask.Message, Swift.Error>) -> () in closure #1 () -> () in react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.scheduleRead() -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
      outlined init with copy of Swift.Result<(extension in Foundation):__C.NSURLSessionWebSocketTask.Message, Swift.Error> in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
  "(extension in Foundation):__C.NSURLSessionWebSocketTask.send(_: (extension in Foundation):__C.NSURLSessionWebSocketTask.Message, completionHandler: (Swift.Error?) -> ()) -> ()", referenced from:
      react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.write(data: Foundation.Data, handler: (Swift.Error?) -> ()) -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
ld: symbol(s) not found for architecture x86_64

unexpected element <service> found in <manifest>

Hi, just installed react-native-mqtt and first thing after doing it, is an error

"<MY_APP_PATH>/node_modules/react-native-mqtt/android/build/intermediates/library_manifest/debug/AndroidManifest.xml:16:5-17:15: AAPT: error: unexpected element service found in manifest."

.
Steps to reproduce:
It's freshly initialized app, no screens, no source, just default App.js.
react-native init MyApp
Install packages for which application asks via npm install.

'variant.getJavaCompile()' is obsolete...

I've been receiving this warning. Though my app is building correctly, i'm afraid of what it could cause in the future.
As far as the warning tells me, the problem is on 'android/build.gradle' at line 111.

image

How to config the tls options

I want to connect aws iot core like as mqtt client. But i don't know how config the tlsoptions, could anyone meet the same issue?

the source code is bellow:

` // MQTT 客户端选项
const options = {
clientId: 'mqtt-client-' + (Math.floor((Math.random() * 100000) + 1)),
reconnectPeriod: 30 * 1000,
qos: 2,
enableSsl: true,
tls:{
caDer: this.fetchCaDer(),
cert: this.fetchCert(),
key: this.fetchPrivateKey(),

    }
};



const client = new Mqtt.Client("mqtt://xxx.iot.us-west-1.amazonaws.com:8883");

client.connect(options, err => {
  console.log("GrillUtils connect err = " + err.toString())
  console.log("GrillUtils connect err = " + JSON.stringify(err))
});

client.on(Mqtt.Event.Message, (topic, message) => {
  console.log('Mqtt Message:', topic, message.toString());
  console.log("GrillUtils message topic = " + topic + " data = " + data)
  this.subscribeState = true
  this.connected = true;
  this.selfCheck(CheckStatus.FOM_HEART_BEAT);
  if (data.value.hasOwnProperty("result")) {
    this.convertResultTopic(data);
  } else if (data.value.hasOwnProperty("heat")) {
    this.convertHeartbeatTopic(data);
  } else {
    //don't care other heartbeat data.
    this.convertSubscribeTopic(data)
  }
});

client.on(Mqtt.Event.Connect, () => {
  console.log('MQTT Connect');
  console.log("GrillUtils connect ")
  client.subscribe('heartbeat/' + this.grillID, (err) => {
    if (err) {
      console.log('Error subscribing to topic:', err);
    } else {
      console.log('Subscribed to topic');
    }
  });
  // 订阅主题
  client.subscribe('result/' + this.grillID)
  client.subscribe('command/' + this.grillID)
});

client.on(Mqtt.Event.Error, (error: string) => {
  console.log('MQTT Error:', error);
});

client.on(Mqtt.Event.Disconnect, (cause: string) => {
  console.log('MQTT Disconnect:', cause);
});

///tlsoptions
fetchCaDer(){
const startLabel = "-----BEGIN CERTIFICATE-----";
const endLabel ="-----END CERTIFICATE-----"
return ${startLabel} MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF ... ${endLabel}
}

fetchCert(){
const startLabel = "-----BEGIN CERTIFICATE-----";
const endLabel ="-----END CERTIFICATE-----"
return ${startLabel} MIIDWjCCAkKgAwIBAgIVAKYgDNHgFHvnaJJhb9d0DmqOd0KwMA0GCSqGSIb3DQEB ... ${endLabel}

}

fetchPrivateKey(){
const startLabel = "-----BEGIN RSA PRIVATE KEY-----";
const endLabel ="-----END RSA PRIVATE KEY-----"
return ${startLabel} MIIEowIBAAKCAQEAtTA7FQ2Yopw3aQ3w0EBzQj0nmERQGW5FYRTsSlEBBijx9/ge ... Ew18DGPwHBLDhC9FrlHAcXsLOrESj6V+WCshz45nLbe2E+3T9MB0 ${endLabel}
}
`

libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)

"(extension in Foundation):__C.NSURLSessionWebSocketTask.send(_: (extension in Foundation):__C.NSURLSessionWebSocketTask.Message, completionHandler: (Swift.Error?) -> ()) -> ()", referenced from:
react_native_native_mqtt.CocoaMQTTWebSocket.FoundationConnection.write(data: Foundation.Data, handler: (Swift.Error?) -> ()) -> () in libreact-native-native-mqtt.a(CocoaMQTTWebSocket.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.