Serial communication with ELM327

I am attempting to have a Photon2 sending simple AT commands and reading back the response but I keep hitting a brick wall. My photon2 is connected to a CP2102 USB to UART converter which is in turn connected to a USB type ELM327 using an OTG cable adapter.
Pin D5 of the photon (RX) is connected to the TX of the CP2102 and pin D4 (TX) is connected to the RX pin of the CP2102. I then connect my Photon to my phone using yet another OTG adapter so that I can power the devices and read messages through a serial monitor app on my phone. The commands are being sent but no response is being detected. I know the wiring is OK because if I connect the USB output of the CP2102 to a serial monitor, I can see the ATZ commands being issued. I also know the ELM327 unit is working because if I connect it directly to the serial monitor phone (through OTG cable) I can issue ATZ and other commands and get a proper response. I am using the code below. Is there something glaringly obvious that I am missing and is stopping me from receiving a response from the ELM327 unit?

Out of desperation, I also tried using a simple gender changer instead of an OTG cable to connect to the ELM327 but that didn't work either.

#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);

void setup() {
  // Start Serial communication for monitoring at 9600 baud
  Serial.begin(9600);

  // Start Serial2 communication for ELM327 at 38400 baud (adjust if necessary)
  Serial2.begin(38400);

  // Give the ELM327 some time to initialize
  delay(2000);
}

void loop() {
    getSetAtCommand("ATZ");
    delay(1000);
}

void getSetAtCommand(String command) {
  Serial.print(command + ": ");
  String added_command = command + "\r\n";
  Serial2.print(added_command);
  delay(1500);
  while (Serial2.available()) {
    Serial.write(Serial2.read());
  }
}

That's not usually how the read loop works. Normally you wait for a delimeter like a newline, or a timeout. This code probably isn't quite right either, but it would be interesting to see if it prints anything:

void getSetAtCommand(String command) {
	Serial.print(command + ": ");
	Serial2.println(command);

	String s = Serial2.readStringUntil('\n');
	Serial.print(s);
}

As a matter of fact, that is how I initially tried to read data from the ELM327. Nevertheless, I tried again using the function exactly as you suggested but still no luck.

Not sure if this is relevant to the issue at hand but the USB ELM327 device does not get the power from the OBD-II port (unlike the bluetooth version). Therefore, to provide power to it I needed to connect the 5V pin on the CP2102 device to the USB pin on the Photon2. Doing that makes one of the lights on the ELM327 device turn on. The effect is the same irrespective of whether the ELM327 is connected to the car's OBD-II port.
If the ELM327 is not connected to the car's port but is connected to my phone through OTG it has the same effect, with the only difference that if I issue an "ATZ" command I get a response reading "ELM327 v1.5".
I am sharing this in case it might shed some light.

Does your CP2102 really support USB OTG? It's a USB to UART bridge, but it's normally used as a USB device, connected to a computer (USB host). Your ELM327 is a USB device. You have a device and a device, which isn't a valid combination.

It works on your phone in OTG mode, but OTG requires more than just the cable - the phone-like device has to support USB host mode and supply power. That's the reason you can't just plug a USB OTG cable into the Photon 2 USB port.

Also the reason the power is behaving that way for you is the 5V line on the CP2102 is probably directly connected to the USB 5V line. It's normally a power out from the CP2102. By connecting it that way, it's acting as a power in, which, when combined with the USB OTG cable, is powering the ELM327. But it's still not a USB host so there's no data transfer.

That explains a lot of things. I was under the wrong impression that the CP2102 would bypass the inability of the Photon2 to act as a host. I clearly have a poor grasp of how USB hosts and OTG cables work.
So is there really no way to get a Photon2 to communicate with USB ELM327?

I would use the ELM327 RS232 version and a MAX3232 RS232 to 3.3V TTL level shifter. This is one on Amazon that's cheap, but I've never used that one. But whatever one you choose will probably look like that. That adapter is a DB-9 female DCE (connects to a computer, the DTE), but I'm guessing the ELM327 is also the DCE so you may need a DB-9 null-modem adapter.

Would something like this bypass the need of an RS232 adapter?

I have previously tried a bluetooth connection but that was a dead end. Also considered a wifi connection but that is out of question because it would require the photon to connect to the ELM327 AP which I believe forfeits the possibility to upload the readings through the regular AP on the vehicle.

Yes, that looks like it would work. Just be sure to connect VCC on the adapter to the Photon 2's 3V3, not VUSB (5V).

The adapter says it works at 3.3V and presumably the instructions say to connect it to 5V only because the Arduino is 5V.

Thanks. Will take a while for it to arrive from Australia, but I don't think I have any other options at this point. Could not find an equivalent from Europe.