【问题标题】:how to send and receive data from nodemcu? [closed]如何从nodemcu发送和接收数据? [关闭]
【发布时间】:2020-03-11 07:20:10
【问题描述】:

我想开发将数据发送到 nodemcu 的 android studio 应用程序,并且我想将数据接收到 android textview。 或使用蓝牙模块的相同功能。因为使用蓝牙模块,我可以使用 android 应用程序控制 led。但我不知道如何在 android 应用程序上接收它。 有人可以帮忙吗?

【问题讨论】:

  • 蓝牙通信有两种方式BluetoothBle
  • 我要使用蓝牙模块
  • 如果可能,请提供任何代码 sn-p 或与从 nodemcu 接收数据到 android 应用程序相关的想法

标签: android bluetooth textview communication nodemcu


【解决方案1】:

如果你想联系classic bluetooth,那么你需要做一些事情。

(假设您已经配对了设备,或者您可以直接通过设备的设置进行配对)

  1. BluetoothAdapterBluetoothManager扫描设备

    val bluetoothManager = context.getSystemService(Context.BLUETOOTH_SERVICE)

    val bluetoothAdapter = bluetoothManager.adapter


  1. 通过BluetoothAdapter.bondedDevices获取你想与之通信的设备

    val bondedDevices = bluetoothAdapter.bondedDevices

    val device = bondedDevices[any](bondedDevices 类型为 Set)


  1. 调用createRfcommSocketToServiceRecord()创建Socket连接

    val socket = device.createRfcommSocketToServiceRecord()


  1. connect 套接字之后,您可以从该套接字发送/检索outputstream/inputstream,最后是disconnect 连接。

    socket.connect()

    ...

    your comminucation here with socket.inputstream()/socket.outputStream()

    ...

    socket.disconnect()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 2014-10-05
    相关资源
    最近更新 更多