Having problems with getting data to show on LCD-screen (4x20)

Hi!

Talked with support they can’t help me anymore than they have, I am sure that my parsing is good, but there is a problem with the code (I think) if there is nothing wrong with the Webhook, the format is in JSON and the webhook worked before but i just don’t know how to get any data to come from the webhook sent to the particle and shown on the lcd screen.

I have changed the code (put the basic code given by in the console) i have switched particles (tried with another one didn’t work (and yes the webhook settings are set to any device), I talked to support I srsly don’t know what to do anymore and I have been working on this project for like 6 months now, HELP!!!

My code --> https://pastebin.com/KhEhrDjn

The first thing I noticed looking at your code was the blank in your event subscribtion

  Particle.subscribe("hook-response/Pub Trans", parseData, MY_DEVICES);

IIRC you should not use blanks in the subscription (nor in the publish).

https://docs.particle.io/reference/firmware/photon/#particle-publish-

Also be aware that this may - over time - lead to problematic behaviour due to heap fragmentation

    char *mutableCopy = strdup(data);

The final free(mutableCopy) won’t prevent fragmentation. I’d rather suggest

    char mutableCopy[strlen(data)+1];
    strcpy(mutableCopy, data);

And what is this line supposed to do :confused:?

String data = String(data);

Apart from the fact that it doesn’t make sense, you should also avoid using String due to it’s internal use of dynamic memory and consequently to potential for heap fragmentation again.

4 Likes

Yeah the String(data) thing was left there from when I was troubleshooting to try and get any data respons,

Anyways now I have 2 errors, one in relations to the mutableCopy:
pubtrans.ino:29:12: ‘mutablyCopy’ was not declared in this scope

and another one which I don’t really know how to fix:
pubtrans.ino:48:67: no matching function for call to ‘CloudClass::publish(const char [23], void (&)(const char*, const char*), Spark_Subscription_Scope_TypeDef)’

And the String was suggested to me from the documentation so thats why I used it, if you have any suggestions, please write!

Thank you in advance again!
Oliver

I guess the error message clearly states the problem (i.e. typo - which I now corrected in the original post).

For that error message, we’d need to see how your code looks now.
Judging by the error message I’d expect something like that …

  Particle.publish("PubTrans", parseData("...", "..."), PRIVATE);

… which is not how you would publish an event especially since parseData() does not return anything, you can’t use its return value in place of an expected const char* parameter :wink:

BTW, with your original code you never actually set data to anything useful, so what data do you actually intend to publish?

1 Like

the code looks pretty much the same form the fact that i put the suggested, just to get any data tbh

https://pastebin.com/KhEhrDjn

and the parseData is just without any paremeters…

Edit: posted to quickly, forgot the pastebin with the new code…

As I said, you cannot pass the function as a parameter for Particle.publish().

If you want to test your subscription handler and not want to trigger the webhook you’d just write

 Particle.publish("hook-response/PubTrans", "2,123;2,456;2,789", PRIVATE);

If you want to trigger the webhook without any data payload you’d write

 Particle.publish("PubTrans", PRIVATE);

That was a stupid type-o on my part when I actually had worked out my code, before I gave up a while ago, I didn’t have the handler function in the publish part just in the subscribe part of my code…

the other suggestion about the

    char mutableCopy[strlen(data)+1];
    strcpy(mutableCopy, data);

The problem that I had was that I didn’t know where to put the code, so If you could tell me where you actually meant for me to put it would be awesome.

My code looks like this now:
https://pastebin.com/KhEhrDjn

As my code looks like now I have other problems than previously mentioned, why I tried to start a new topic but I will continue it here now since this is not stackoverflow and I don’t have to care of starting a new topic every time my hands itch.

The main problems now are these: On my lcd the three lines of next times when the bus is going to arrive are not showing (my lcd is 20x4) and the one time that is showing sometimes just “times-out” and stops showing anything…

E.g. it shows

Next buses:
5 min

and then

Nexti buses:
4 min

and then nothing for some reason and then maybe again

Next buses:
Nu (which means “Now” in swedish)

Any reasons why this might happen, and any ways I can make my particle get a better and faster connection to the webhook, since I feel like it’s taking a long time for it to receive the hook-response.

Thanks in advance

1 Like

These two lines should replace the strdup() line (#18 in your pastebin) and you’d need to remove the free(mutableCopy) line from the handler.

For the String data = String(data); issue, you can remove that entirely - since you are not actually using data for anything - and just write Particle.publish("PubTrans", PRIVATE) as said above.

To address your other question we’d need to know what the actual input data you are receiving is when that happens.
For that you may want to Serial.print() the entire data string and post it here - or give us a link to the service you are getting the data from, for us to request a set ourselves.

The timing of the webhook response depends for a big part on the time the target server needs to reply. If you watch the event log in console.particle.io/logs you should get a feeling for where most time is lost - it shouldn’t be the device<->cloud communication.