在 React-Native Expo 上接收 MQTT 消息

Receive MQTT messages on React-Native Expo

我试过以下库:

react-native-native-mqtt
react-native-mqtt
react_native_mqtt
sp-react-native-mqtt

他们中的大多数给了我同样的错误:

null is not an object (evaluating 'Mqtt.createClient')
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:293:29 in invoke
- node_modules/regenerator-runtime/runtime.js:63:36 in tryCatch
- node_modules/regenerator-runtime/runtime.js:154:27 in invoke
- node_modules/regenerator-runtime/runtime.js:189:16 in PromiseImpl$argument_0
- node_modules/react-native/node_modules/promise/setimmediate/core.js:45:6 in tryCallTwo
- node_modules/react-native/node_modules/promise/setimmediate/core.js:200:22 in doResolve
- node_modules/react-native/node_modules/promise/setimmediate/core.js:66:11 in Promise
- node_modules/regenerator-runtime/runtime.js:188:15 in callInvokeWithMethodAndArg
- node_modules/regenerator-runtime/runtime.js:211:38 in enqueue
- node_modules/regenerator-runtime/runtime.js:238:8 in exports.async
.... its pretty long and probably says nothing of value.

没有给我这个错误的;给了我关于套接字和缓冲区的错误,几乎就像它试图通过网络套接字运行它一样。

我做错了什么?

甚至可以在 android react-native 上获取 MQTT 消息吗?

是世博会的问题吗?

我遇到了同样的问题。一个世博会项目,害怕被世博会驱逐。

我的实际解决方案从这里开始!

经过大量研究,我找到了这个模块。 Eclipse Paho MQTT Client for JS

npm i paho-mqtt

Expo 小吃示例:

https://snack.expo.dev/@rizwanamjad/mqtt

https://snack.expo.dev/@eseg/mqtt