从 iPhone 向微控制器发送信号

Send signal from iPhone to a microcontroller

我觉得这应该是一项基本且简单的任务,但我正在努力寻找可以提供帮助的资源。 我想将整数值发送到同一网络上的 IP 地址。 我相信实现此目标的最佳方法是通过 UDP 消息? 接收设备通过wifi连接。

如何在使用 objective c 的 iPhone 应用程序中实现这一点?

有很多方法可以实现您的需要(例如,您可以 运行 探索板上的 Web 服务器并从 iPhone、运行 telnet 服务器连接,打开套接字连接等)。

但是既然你已经说过 UDP 传输是你想要的,我建议你看看 UDPEcho example or even better AcynchUDPSocket class,它提供了你需要的所有功能:

Native objective-c, fully self-contained in one class. No need to muck around with low-level sockets. This class handles everything for you.

Full delegate support. Errors, send completions, receive completions, and disconnections all result in a call to your delegate method.

Queued non-blocking send and receive operations, with optional timeouts. You tell it what to send or receive, and it handles everything for you. Queueing, buffering, waiting and checking errno - all handled for you automatically.

Support for IPv4 and IPv6. Automatically send/recv using IPv4 and/or IPv6. No more worrying about multiple sockets.

使用 cocoapods 很容易将它添加到您的项目中,您会在 git 存储库中找到很好的示例。

我建议您从 UDP 广播开始。

希望对您有所帮助...