How do you communicate to a Modbus device within an iPhone application? - iphone

I would like to be able to develop an iPhone application that can communicate with Modbus devices, but I'm not sure how to proceed. Has anyone had experience with this or are there existing libraries out there for this purpose?

You will need first to know how to make a simple TCP client on your iPhone, and a simple TCP server on your computer that your iPhone client will talk to via WiFi. Make sure PING command works and firewall does not block your server port before any client/server experiments, and make sure that server port for experimenting is greater then 1024 and not already used. Then take a look at MODBUS TCP specification from official site, get familiar with function codes you are interested in, and study C code found here. Then make a simple MODBUS TCP client that can send a request to MODBUS TCP server and interprete an answer. The best way is to start reading single register value, then progress in time and add more functions.

I do exactly all above points, my iOS Modbus lib works fine, application is now up on AppStore, PLCLink read and set any modBus data into my Wago home automation.
Installation guide : http://pautex.fr/plclink

Related

Is it possible to make a good voice call application with OpenSIPs server?

I am building a free voice call application on Android. I used OpenSIPs open source to make a SIP server and successfully make a call to another phone in WIFI network. However, I couldn't make a call when the phone uses cellular network like 3G/4G. I found out that I should make a STUN and TURN server to find exact SIP address.
Someone told me that it is hard to find SIP address if the user uses 3G or 4G network. So, he said I should use SBC to redirect voice data if I want to make good connections. He said I should make redirect servers to have good quality of service.
Is it possible to make a good voice call service with OpenSIPs server? If it is true, is there voice call services who used OpenSIPs open source? I've searched all documents, but couldn't find the answer.
Thank you.
I decided to make a SIP server using FreeSwitch Open Source. It was much better than OpenSIPs. I didn't have worry about NAT problem on FreeSwitch. It is also very easy to install a SIP server on Linux. Check out the website. http://freeswitch.org/

What is the trick used by some iphone sip apps to communicate with UDP only sip servers?

There are some ios sip applications who are able to communicate with a UDP only SIP Server.
As I know iOS allows only TCP connection to remain open in the background but most of the SIP providers are supporting only UDP.
I have noticed that iOS application 3CXPhone has a "NAT helper mode" and it is able to keep the communication in background with a 3CX Phone system who is UDP only. Dose anyone know what trick do they use? I am developing an SIP app and I have to make it work for the UDP only SIP providers.
I know there are multiple questions regarding UDP socket in background on SO but none of them has a useful answer or the solution proposed there dose not work anymore (starting from iOS 6).
Until now I am aware of 2 possible solutions:
1. Use some GPS events and during that events maintain the socket communication too. After that try to trick apple and get your app in the store.
2. Use a SIP proxy in the middle (B2BUA). But in the 3CXPhone "NAT helper mode" I am not seeing any sip proxy configuration.
If you really need a UDP socket you will need a few things:
UIRequiresPersistentWiFi: to ensure that iOS connects to Wi-Fi and doesn't turn it off after some time (I'm assuming you want Wi-Fi as well, if not just ignore this one)
Play an empty audio in the background in a loop to keep your application active.
Have a timer that pops every ten seconds or so and sends a small (e.g. crlf) message to the server.
The last step is needed to keep the UDP connection open in the network. If you don't send anything often, someone in the network (e.g. a router) will close it.
The empty audio file is the only way to ensure you can do something in the background in short intervals (the ten second timer).
After writing all that: this will consume a lot of battery. Users will not leave your app running for long.
Most modern SIP servers support TCP. You should really spend your time on a TCP solution. The UDP one won't be accepted by your users.

Send messages between iPhone & Mac

I'm fairly novice in iPhone development, but trying to create what would seem a fairly simple application.
I want to have 1 program running on my phone/simulator that has a slider and a button, and another receiving program on the mac, such as Processing/Supercollider.
When the button is pressed i want a String such as "hello" to appear in the post window of the program on the mac, and when the slider is moved up/down for an integer, say between 0-99, to correspond with the movement on the phone. I'm assuming a WiFi connection would be essential for the sending of messages between devices.
Does anyone know how I might go about writing this - tutorials/code examples/links to get me started?
Cheers
cocoaasyncsocket is a great wrapper around CFSocket and CFStream, that makes networking much easier. Bonjour has great documentation at developer.apple.com
This should be done over a TCP connection which is established between your iPhone and the PC. For that to happen you need to write 2 pieces of software:
1) A client: to be installed on your iPhone
2) A server: to be installed on your PC
The server will listen to connections coming from the iPhone and once a connection is made you can send messages quite easily between the two.
This will give you a good grasp on the theory
Guide to socket programming in C
Once you have that then you can find tons of Obj-C TCP examples.

iPhone (behind cellular NAT) peer-to-peer internet connection with a server

I have an iPhone on a 3G cellular network and a server on the internet and I want them to be able to exchange messages bidirectionally. Sometimes the iPhone makes a request to the Server some other times the Server makes a request to the iPhone. Problem is that the iPhone is behind the NAT of the cellular network and it doesn't have a fixed ip:port , on every new connection the port changes.
I think I have to make a bidirectional socket SO_REUSEADDR/SO_REUSEPORT and make the connection persistent.
The other two solutions are Apple's Push notification and long polling, for now I need an answer for the P2P solution between the iPhone and the Server.
Can you advise me on what I have to do or provide me a working example code where an iPhone can receive messages from a host that is on the internet?
It is a pity that Java is not supported on the iPhone, because the JXTA framework would have solved your issue easily.
What you are looking for is a TURN like implementation of P2P. The Iphone has to initiate the connection to the server to punch the hole in the NAT and yes, it has to be kept alive (even if you investigate more sophisticated implementations like STUNT for NAT traversal).
With TURN, the server has to transmit messages between IPhones, with STUNT, messages are transferred directly between devices, but it is quite complicated to implement properly.
i've been doing a lot of reading up on these things and my understanding is that XMPP is the solution for you. use an open source XMPP server (like openfire) and XMPPframework (an ios module).

Raw sockets permission IPhone?

I'm discovering capability of Iphone network programing. I have already working ICMP ECHO REQUEST / REPLAY using SOCK_DGRAM. And I would like to do more stuffs. For example port scan in NMap. Yes, I can use TCP connect(). But I wanna try to send TCP SYN.
My question is, can use raw sockets ? Because Iphone doesn't have root permission. And Unix Os need permission to use raw socket. But I found somewhere, that I can use SOCK_RAW and build own IP Header. Allows this Apple ?
Thanks for any reply.
You can't do that inside the SDK. If you are building a jailbreak app you can do this without any problem, probably you will need some headers, including the UDP header and possibly some BPF if you want to sniff packets (like tcpdump, which you can find a iPhone version on Saurik's repository) that are not present on the SDK. You can just copy them from Mac OS X (/usr/include) and put them on /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/usr/include/ for example.