Electron TCPClient not working anymore since 02.28.2017

Hello everybody!

I have two Electrons (firmware 0.6.0) that post (actually using GET method) some data to a site of mine hosted at GoDaddy.

It’s something very simple and it worked well until 02.28.2017 for one of them. The other one was powered off during 02.26.2017 and 03.03.2017, so I don’t now if it stopped the same day as the other one.

Here’s what I do:

  byte server[] = { 160, 153, 162, 19 };
  char szRequest[255];

  sprintf(szRequest, "\"GET /bees/telemetry?dev_id=%d&vbat=%.2f&vcap=%.2f&rssi_rssi=%.2f&rssi_qual=%.2f HTTP/1.0\"", dev_id, fVBat, fVCap, fRssi_rssi, fRssi_qual);
  Serial.println(szRequest);

  Serial.println("connecting...");

  if (client.connect(server, 80))
  {
    Serial.println("...connected");
    client.println(szRequest);
    client.println("Host: bornuz.com");
    client.println("Content-Length: 0");
    client.println();
  }
  else
  {
    Serial.println("connection failed");
    delay(1000);
  }

They connect, (flash Green, breathe Cyan, but now the response is 400 Bad Request, followed by a http formatted response that includes the line:

(none)/bees/telemetry?dev_id=2&vbat=4.04&vcap=97.50&rssi_rssi=-81.00&rssi_qual=43.00 (port 80)

I’ve set up two destinations on my server, one as a simple PHP script, at /direct/up2.php and one as a CodeIgniter Controller at /bees/telemetry. Both worked fine…
I am using a Vodafone SIM.

The only change after 02.28.17 was thet I installed Node-Red. During install I had to update my node.js and npm installations.
(I would like to completely uninstall everything related to my local setup and after that to do a fresh reinstall, but I don’t know how. I think I should uninstall-reinstall everything because:
I also have another problem:
If I compile my code or Tinker in cloud with WebIDE and download the firmware, I can upload that firmware to my Electron with particle-cli and it works as described above. Same with Tinker, but Tinker works well.

If I compile in cloud from my local Atom IDE, I am able to upload the firmware to Electron but it flashes green a few times and after that it gets stuck breathing Magenta. Same with Tinker. )

I really need some help. Many thanks in advance!

I would not rely on println() to end the request string correctly.
I’d rather use print() (or write()) and add the required \r\n\ explicitly.

Or you use the HTTPClient library to take care of the correct format.

This indicates that you don’t have 0.6.1 installed on your Electron. While CLI & Web IDE can build for other versions (like your 0.6.0) Dev (currently still) build for the most recent release version (currently 0.6.1).


Update:
I just downloaded the most recent Dev version and it now also supports version targeting :+1:

How? Can you, please, give me a hint?
Thank you for the print()(write()) +"\r\n" suggestion.
(My code is a copy/paste from the firmware docs)

The lib and the sample usage can be seen here
https://build.particle.io/libs/HttpClient/0.0.5/tab/example/application.cpp

Well, thank you @ScruffR ! I have solved two of my problems thanks to your answers.

Using HttpClient I managed to write a new firmware that NOW works, and,
Reading again and again your answers I realized that I do not have the last release of the Desktop IDE.

After installing it I can now compile in Cloud and flash (–serial & --usb) the new firmware.

There is still a mystery: Why my old code (listed in my first post) with Particle’s TCPClient worked and now does not work anymore?! Is the continuous development of Particle’s System Firmware and API an explanation for such … incidents?

Anyway, thank you again!

1 Like

I can’t be certain but it could well be that your code should never have worked as it was, but some loophole in the framework did allow for it to work. And as it happens, these loopholes do drop off their perch unexpectedly from time to time.