Android 的 MQTT 代理

MQTT broker for Android

有人知道在 Android 智能手机上运行的 MQTT 代理吗?我尝试 Google 并没有找到任何东西,而且在应用程序商店中似乎只有一个应用程序只有 10 次下载,所以我不确定它的效果如何。

这里是我适配的一个MQTT代理库Android:https://github.com/interaktionsbyran/moquette 不过,您必须制作自己的 Android 应用程序,它只是一个库。

将这些依赖项添加到 gradle

    dependencies{
   compile 'io.moquette:moquette-netty-parser:0.8.1'
    compile 'io.moquette:moquette-broker:0.8.1'
    compile 'io.moquette:moquette-parser-commons:0.8.1'
}

并使用

io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();

启动代理服务器。默认 URI 是 tcp://localhost:1883

对我来说 server.startServer(); 给了我例外,因为它无法创建文件 BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME。 所以,我更改了 BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME 的目的地 在代码下方使用此代码,它对我有用。

     try {
         MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
    server.startServer(memoryConfig); 
        // server.startServer();//is not working due to DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME; 
        Log.d(TAG,"Server Started");
         }
         catch (IOException e) { e.printStackTrace(); }
         catch (Exception e){ e.printStackTrace(); }

并为 android

使用 Paho 库
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

创建客户端并连接到 tcp://localhost:1883 并订阅主题并开始发布和接收消息。

moquette library for android.

I have developed an App specifically for this , please download here -

It has inbuilt broker and client too..all for free , connect your devices to android phone via hotspot or wifi.

https://play.google.com/store/apps/details?id=server.com.mqtt

您可以在 Termux 终端中 运行 mosquitto mqtt 代理。

  • 安装Termux using e.g. F-Droid
  • Open/run Termux 终端模拟器
  • 安装蚊子

    pkg install mosquitto

  • 在终端内启动 mosquitto

    mosquitto

就是这样。服务器将监听默认端口 1883。 配置见 mosquitto.