I have a Wifly module that is in AdHoc mode (i.e. it creates its own local wifi network) and I would like to program into my iOS app the ability to connect to the Wifly and send data back and forth.
When communicating with the Wifly from a computer, you have to send command through a terminal emulator. Does anyone know how to do this from an iOS app?
Thanks
You (or your user) first need to connect manually to the ad-hoc Wifly network in the wifi settings. Then, to communicate from your app to the Wifly, you need to open a TCP or a UDP socket and send messages through it. I used the excellent CocoaAsyncSocket library to do that:
https://github.com/robbiehanson/CocoaAsyncSocket
Configuring the Wifly radio correctly was the most difficult part, the documentation is horrendous. But here is an example config from my web site that works well for an iPhone app:
http://www.curiousmarc.com/dome-automation/building-marcduino-boards/setting-up-the-wifly-radio
Edit 08/2014: the new WiFly firmware 4.01 and higher has deprecated the use of ad-hoc, the WiFly can now be configured as a real access points. Makes life simpler. New configuration instructions for the WiFly are on my website above. The rest remains the same, open a TCP socket and away you go. What you send comes out to the serial port on the WiFly.
Edit 03/2017: I had reliability problems connecting to the WiFly, it's very flaky in access point mode. Switching to the much better Xbee S6B radio solved the communication problems.
Using Wifly,
Once your iOS device is connected to the wifly Ad-Hoc network (And it can, through "Settings", outside your app), your app can initiate a TCP Socket Client to the Wifly local network ip on port 2000 (by default), from there, you can proceed normally as if you were communicating via serial+terminal
Using the established TCP Socket, you can pass the wifly into "CommandMode" (If you want to config it remotely) by writing $$$ to the TCP Socket stream, or you could simply communicate with it by sending data to the stream.
Note: If you don't know the local ip address of your wifly, you can config it through serial after by using the "CommandMode".