mickeyl / LTSupportAutomotive

An iOS / watchOS / macOS support library for OBD2, VIN-Decoding, and more.
MIT License
212 stars 59 forks source link

How to set IP address to connect OBD ELM327 through Wifi? #43

Closed lygialiem closed 1 year ago

lygialiem commented 1 year ago

Hi team.

First of fall, thank you for your good library. But I can't find any code to set IP address to connect to another OBD2 ELM327 emulator for testing?

Thank you very much.

mickeyl commented 1 year ago

Hi @lygialiem. This library is connection agnostic, hence it doesn't care about the way the bytes are incoming, all it needs is a pair of NSInputStream and NSOutputStream when you create the adapter like that:

LTOBD2AdapterELM327* adapter = [LTOBD2AdapterELM327 adapterWithInputStream:inputStream outputStream:outputStream];

That said, if you're talking to an OBD2 WiFi device, you can obtain a pair of streams using the Foundation's NSStream API, e.g. like that:

NSInputStream* input = nil;
NSOutputStream* output = nil;
[NSStream getStreamstoHost:[NSHost hostWithName:@"192.168.1.10"] port:35000 inputStream:&input outputStream:&output];

and then feed input and output into the aforementioned constructor.

Hope that helps.

lygialiem commented 1 year ago

Hi Mr mickeyl

Thank you for your well response. I've already make it work. I close topic now.