Custom Vin Reader App (App works fine, but not when imported to my script)

I’ve decided to purchase a Carloop Wifi (With the Photon).

Up until now I’ve only bee playing with the Photon functionaility and have been able to get what I am looking for from this.

I am now moving onto the Carloop section and this is where i’m struggling. When trying to read any data from the carloop from my app I don’t get any response back at all.

I uploaded my source code to: BitBucket/jnymris/carloop

I’ve tried to add as much debugging as possible and I can see it appears to get this far:

(Line 101) Particle.publish(“Debug/Status/readVIN()”,“starting”);

But does not appear to reach any further. Using the (Vin Reader App this appears to pull it successfully?

Any suggestions as to where i am going wrong?

A few people on here Have posted about that on here, check your baud rate and maybe if your can or extended frame format.
Try to flash the socketcan sketch and see if you can read any data like that.

@dubb45 Thank you for the quick response.

Using the Vin Reader App it is able to pull my Vin which suggests the baud rate/exnteded frame format is okay (otherwise this would fail). The code i am using is basically a copy/paste of that, which points to a programming error somewhere rather than a baud rate/extended frame format?

It’s probably more likely something I’ve missed out, but cannot find where.

@jnymris, I took a look at your code, and there are a few fundamental Photon programming issues.
In cases like this, I would suggest reducing your code to a single functionality and focus on getting that going.
Once you get one functionality, then add on the next one. At the moment, you have a whole lot going on and we do not know exactly which function is the issue.

Can your provide a list of your debug outputs? You tell us how far it gets, but it is also important to tell us how it got there and the timing.

Here are my observations of your code, which may or may not be the cause of the problem you are seeing:

  1. For the #include “carloop.h”, I do not see the comment // This #include statement was automatically added by the Particle IDE. This makes me wonder if you added this library to your project, or if you just added the include statement? Make sure you added the library, the same way as the other libraries.

  2. In your setup() function, you need to have any declarations of Particle.function (or Particle.variable) at the very beginning. These can only be registered with the cloud within a couple of seconds of connection. Certainly having these after a Particle.process() will pretty much guarantee it will be too late to behave correctly. This is one of those cases where it is not obvious, but it is documented.

  3. You need to check the documentation on the rate limits for Particle.publish(). Depending on how fast your code runs, you are probably publishing way above the rate limit. The Particle cloud cuts you off for a cool-down period when you exceed the rate limit. That way, you are missing the publish statements and cannot successfully debug.

As an alternative, send your debug statements using a serial connection over USB with Serial(). EDIT: There are acutally some Serial.println() calls in your code that do this. That way you can use a terminal program (such as PuTTy) to capture all the debug statements on your computer, save them as a text file, and not blast the cloud with a whole lot of publishes.

  1. Your use of Strings is not going to work as you expect.

Unfortunately, small microcontrollers do not have memory management and do not sweep up the trash in memory, unlike a full-blown operating system. As a result, using any more Strings than absolutely necessary increases the amount of memory wasted away. When the memory is full, then the Photon starts to behave strangely. This is a common mistake that almost everyone makes once with microcontrollers; including me!

Most of the time, when a String function is used (such as concatenating two Strings), the memory keeps track of the new resulting String (the newly concatenated String), but abandons the originating Strings in memory (the two Strings that were to be concatenated together). It is amazing at how many Strings will be created, and how much memory is used up and abandoned.

To use Strings, which you will sometimes need to, make sure you use the String handling functions that will do the job with the fewest number of operations.

Recommended practice is to use a char array big enough to hold your data, and work within that as much as possible.

  1. At the end of your setup() function, you wait for WiFi and cloud connection. However, you already did Particle.publish functions which require a cloud connection. Actually, your code never sets the SYSTEM_MODE, which means it is running in the default Automatic mode. In Automatic mode, the code will not run until the cloud is connected. Assuming Automatic mode is okay for you, you can get rid of those waits.

  2. Watch out for the correct When you request the VIN of a car, it is usually going to come from the BCM (Body Control Module) and not from the ECU (Engine Control Unit). Your code might be okay, or it might not, depending on the car.

Work on that for a start. Once we get a log of the debug statements, then we can help dig in deeper.