I need a little help with a sketch using Arduino IDE

Unfortunately I don’t understand that WaitFunc code or the FlashRedLED code or how it is supposed to work. I will have to look for an example of a simpler code for this function. One I understand.

I tried putting in additional debug messages in the OnDataRecv, but it was not able to compile them.

G’day Marvin,

I have just spent a few days learning how to combine sketches and also had a slow start. I haven’t read this entire thread, but the method that worked for me was:

Take the separate sketches
Sketch A
Sketch B

Then add sketch B one bit at a time into sketch A. For example:

Sketch A libraries
*Sketch B libraries
Sketch A setup
Sketch A loop

Then compile, upload, give code and error messages (if any) to ChatGPT for solution, implement solution.

Then the next bit of Sketch B:

Sketch A libraries
*Sketch B libraries
Sketch A setup
*Sketch B setup (copied and pasted after the A parts, but still inside the one setup bracket. I.e. don’t have 2 setup sections)
Sketch A loop

Compile, upload, etc.

Tell me if my explanation doesn’t make sense, because it did work for me when combining an NTRIP Client and Digital Compass.

1 Like

Hi All

Be a little bit careful here. Sometimes somehow (in the control of the Gods) this does not work as expected and you could get some funny (I mean you can’t find the cause) errors when compiling. The cure seems to be very carefully type in the code. Seems you can somehow pick up or introduce some hidden (non printable???) beasties during the process. I have had to do this with a complete sketch at one time. When copied and pasted it just would not compile.
Cheers Bob

1 Like

Thanks Jacob
The sketch compiles without error it just doesn’t run the way I expect it to. But I am a novice, so that doesn’t mean much. . . When I add the second part of the code to the original sketch the first sketch seems to get stuck after it runs the second sketch. . . . I’ve been trying to figure it out for several days with no luck.
I might give chatgpt a go, although I’m not sure how to explain to a computer what is not working with my code :crazy_face:

You won’t figure it out without much more information. You haven’t added enough debug statements, and your debug statements aren’t giving you the full picture. You need at least one for every start and end of a method, and one for every time through any loop. And mostly they should show at least one variable that is relevant to what is happening (eg, argument to a method, result of a method, counter or other exit condition for a loop). When you have enough information the picture will become clearer. Then you can get assistance with resolving it.

1 Like

Now that you mention it, I did find it very very useful to put serial.print(“ [Whatever just happened] ”) after basically everything. Definitely a good idea. Also helps ChatGPT figure it out if you can tell it what line it stopped at.

Also, on the point about not being able to explain. You can just type “the following code is not working. It just hangs. I think the problem is in the loop section. [Paste whole sketch]”.

1 Like

Thanks Jeff
I have more debug statements than I know what to do with :crazy_face:

The code I have on Github doesn’t include the numerous debug statements that I recently added.

Still not having any luck. :confused:

Thanks for the suggestion to try ChatGTP>

This is what ChatGTP returned:

It’s difficult to say for certain without more information, but one thing that stands out is that the http.POST() method is being called with the url_1 variable, which contains the URL used to initiate the HTTP connection with http.begin(). This may cause unexpected behavior, as http.POST() should be called with the message to be sent as the argument.

Additionally, you may want to include more error handling in your code to help identify any issues. For example, you could add Serial.println(http.errorToString(httpCode).c_str()); to print the error message if the HTTP request fails, which could give you more information about the problem.

It has me looking down a whole other rabbit hole :thinking:
Reviewing the way that the CallMeBot API works and the syntax. Just one of the problems with a nubie using code that someone else wrote.

Hi Marvin,

Debugging code is an entirely separate skillset and arguably more useful than writing it from scratch. @Jeff105671 and @Jacob213709 have shared some top points though so I’m sure it’s only a matter of time until you locate the issue using their tips.

@Robert93820 's point about copying and pasting code is also something that newbies get stung by all the time. Good text editors won’t do it, but sometimes copying code of a webpage will mangle what gets copied with hidden characters and all sorts of other nonsense. Tabs being converted to space characters is also very common.

As always step 0 is to add more debug lines than you think you could possibly need in as many places as possible.

If you have access to a hardware debugger and can step your code through its operation step by step that can also be a game-changer, but it won’t work in every situation.

If in doubt, go back to the simplest form of code that worked properly, and add the smallest chunks of new code possible, testing as you go.

1 Like