I already know how to establish a wifi connection with the OBD2 adapter, but I have no idea how to request information from it. Like 010C is the command to return the engine RPM in hex form, but how do I even send "010C" to the OBD2 adapter? I can find answers and even OBD frameworks for languages like Java and Python, but nothing for swift. Thanks.
If you have already established a socket communication to the WiFi adapter, then either bind the socket to a pair of NSStreams and send/receive data using those or use the CoreFoundation API or the low-level posix API to send/receive data.
Chances are you might want something more high-level though. I have created an OBD2 library for iOS and macOS at https://github.com/mickeyl/LTSupportAutomotive. It's written in Objective-C and would need Swift bridging headers to make it useful for you, but that might be a good way for you to dive more into the topic.
Our java implementation requires converting String messages, like "010C" or "ATZ" to byte[] and then sending those bytes to the OBD2 adapter. I imagine you'll have to do the same for swift.
Here is a resource on working with OBD2 adapters that may help you: http://elmelectronics.com/DSheets/ELM327DS.pdf
You need to know OBD protocol such as: ISO 9141-2, KW-2000, ISO 14230-4, SAE J1850 and CAN ISO 15765-4 (11 bit or 29bit).
Take a look at this reference to get more information.
You can find PID OBD2 here.
Related
I have a program that uses FIX protocol and the QuickFix engine (in my case, for c++) in order to do inter process communication. My question is, since the data is transferred in plaintext, does the standard of the protocol OR the engine offers a cryptography solution to cipher/decipher the data? Thank you in advance.
You can use SSL with QuickFIX.
https://raw.githubusercontent.com/quickfix/quickfix/master/README.SSL
You could also send data through stunnel. https://www.stunnel.org/
The protocol itself does not offer such functionality although you could specify the encryption method through tag 98/EncryptMethod.
How exactly would one go about creating a raw socket on the MAC layer in Micropython?
The UNIX equivalent is:
eth_p_all=3
netif='wlan0'
s=socket.socket(socket.AF_PACKET,socket.SOCK_RAW,socket.htons(eth_p_all))
s.bind((netif,0))
For one, it is not clear how to get the interface name, and there is no socket.AF_PACKET or socket.htons.
So, if there is no way to do this with the stock libraries or firmware, which libraries should I choose, or if firmware modification is required, how exactly should I modify the firmware?
There have no raw socket implementation at current upy firmware. Yo can check the following line. The raw socket dispatch has been removed from modlwip.c
https://github.com/micropython/micropython/blob/68a5d6fe7746850ce049b8bf295bfce1382383f3/extmod/modlwip.c#L712
If you want to modify firmware by your self, you can follow the steps.
Check your platform's origin SDK support raw socket or not. (for example, cc3200 use TI's cc3200 SDK and it support raw socket)
Modify modlwip.c
There's an unofficial port(realtek's ameba series) support raw socket. You could start from this one.
https://github.com/wylinks/micropython-ameba/blob/ameba/ports/ameba/mphelper/mods/modlwip.c
I have a script that I can configure to either use a socket library or use libcurl. I am using http access methods. When I use the socket library each request takes much longer as compared to when I switch to libcurl. Both of them work though.
I am curious to understand the difference. Is there a way I can look at the raw request and response for the network communication so I can investigate this? Something like what the browser shows for each page request would be ideal.
I am on a windows system. But if there is a software that can work on both windows and linux that would be great. Any help on how I can dig into this would be helpful.
Thanks.
After googling thoroughly I finally decided to post my problem which is really giving me nightmares.
In my app I am trying to connect to a TCP server using the Network Carrier internet and using following connection string:
url="socket://"+ip+":"+port+";deviceside=true;connectionTimeout=30000;apn=;tunnelauthusername=;tunnelauthpassword=;";
I am able to connect to internet through the phone's browser but not able to connect to TCP server through app.
In my device APN authentication is disabled by default and APN,Userid/Password fields are blank thats why i have taken these parameters as blank valued in the connection string.
When i try to connect through wifi network using the string below:
url="socket://"+ip+":"+port+";deviceside=true;interface=wifi;connectionTimeout=30000";
I am able to connect to server but not in the case via APN.
Please help me out.
I am just stuck here and finding no way out.
Thanks
There are a variety of methods of connecting to a Server. What you are doing is specifying the method to use in the connection suffix which you set. The options that you can use in the connection suffix are documented in the BB KB article here:
Different-ways-to-make-an-HTTP-or-socket-connection
If you are supporting really old phones (pre OS 5.0), then this is the only option you have. But the trick with this is that you have to figure out what connection method is going to work on your device at the time you make the request. There is a load of code floating round the internet to do this, most of it dubious.
If you are OS 5.0 or above, then you can use a more advanced API, the ConnectionFactory, to make this easier, and in OS 6.0 even more advanced features. These are all documented on the BB Java microsite, see here:
BB OS Networking
The option you are using is the GCF framework. I recommend you investigate the "Network API" if you are supporting OS 5.0 and later only. You might also investigate the "Network API alternative for legacy OS".
This does not answer the frequent question, "how come the Browser can connect and I can't in my app?". This is because the Browser uses a special BlackBerry connectivity method referred to as BIS-B. The good thing about BIS-B is that it will work for any BB phone that has a BlackBerry tariff, and requires no configuration. The bad thing is that you do not get access to it as of right. To get access to it, the easiest thing to do is to ask for Push support, even if you are not planning on using it immediately but might in the future. This is documented on the page above.
But back to your question. The APN values in your TCP configuration being not set, does NOT mean you don't have to set them. The values specified in the Options are used as the default values should someone code ";deviceside=true" as a connection string - the idea being that users can set these for themselves and application developers don't code anything. These values are specific to your carrier. So search to find out what values you need to use. You will either put these values in the TCP Options (and so don't code them in your connection suffix), or put in your connection suffix. If you can't find out what you should put in there, you need to ask your carrier.
On most BlackBerry tariffs, using direct TCP through the APN may cost the user something for the data, and will also require configuration. Alternatively, you can use WAP 2, which may also cost for data, but doesn't require any configuration. The advantage of both these is that they will work on phones that are not using a BlackBerry tariff.
My recommendation is to look at connecting using ConnectionFactory (Network API), but this will only work for OS 5.0 and above.
I have a TCP server running on a machine. (implemented in Java). I need to connect to that server from a iPhone and send data to the server and also, receive data on the iphone when server pushes me data. So I need to be notified when data pushes from the server.
Is there a way to do this in Objective C(socket programming). Although I googled I couldn't find a solution. But I saw CFSocket etc.
Please anyone have a solution?
after a possible solutions in the internet, I found a nice asynchronous TCP and UDP socket Library here. (http://code.google.com/p/cocoaasyncsocket). This library worked really well for me so far. This wraps the CFSocket and CFStream.
Thanks for your replies.
You can use the CFNetwork family of classes to implement lower level sockets. Apple has an introduction document that describes the use of these classes.
CFSocket calls and similar will let you create sockets. You can then use CFStreamCreatePairWithSocket() to create a CFReadStreamRef and CFWriteStreamRef, which you can cast to NSInputStream* and NSOutputStream*.