HarringayMakerSpace / awsiot

ESP8266 / ESP32 examples with Amazon AWS IoT
53 stars 38 forks source link

Missing Function declaration in ESP32 version #7

Open skaterdude opened 1 year ago

skaterdude commented 1 year ago

I think this declaration is missing: void pubSubCheckConnect();

The Arduino IDE gives me an error like: "pubSubCheckConnect not declared inthis scope" when I compile. If I add the declaration at the top with the others, clean compiles just fine.

torntrousers commented 1 year ago

The Arduino environment should do that automatically. What version of the IDE are you using or how do you do the build?

skaterdude commented 1 year ago

I'm using 1.8.16. Just copy-pasted the code into a new program and updated the certs/keys.

If that's true, then you don't need line 110, right? void msgReceived(char topic, byte payload, unsigned int len);

torntrousers commented 1 year ago

The msgReceived function is different, i think because the PubSubClient is a libraray so not in the same directory as the sketch so the Arduino auto-prototype feature doesn't happen for it.

The code compiles fine for me with Arduino IDE 1.8.19. Is your file type .ino?

skaterdude commented 1 year ago

The auto-prototype feature is not reliable. This post describes one situation where it fails: https://forum.arduino.cc/t/void-arguments-optional/1001858 Perhaps one of the libraries I have loaded in my IDE affects this. I've done tons of Arduino projects, so I have many libraries installed.

Good coding practice would be to include the function declaration to avoid the idiosyncracies of the sketch pre-processor. It's your code. I'm just letting you know that there is at least one case where it fails.

torntrousers commented 1 year ago

sorry this dropped of my notice...

Its not usually necessay to include the function prototypes in the Arduino environment. To me it still seems like something odd or unusual with your environment, would be really interesting to track down what that is if you'd like to debug that further?

skaterdude commented 1 year ago

It's not a problem at all. Just letting you know my experience, and looks like others have had a similar issue with Arduino IDE, though not with this code in particular. If there's something I can provide to help diagnose the issue, LMK.

torntrousers commented 1 year ago

How about make a fresh arduino ide install in a different directory using the portable install approach and try with that to see if it does or does not work?

So, use a version 1 not v2 of the IDE, and the zip install - https://downloads.arduino.cc/arduino-1.8.19-windows.zip

Unzip that to some directory. Before launching the ide create a new directory inside the unziped folder named "portable", so in the same directory as the other arduino directories drivers, examples, tools, etc. This will make the ide put all its install user files inside that portable directory so its issolated from any other ide installs on the computer.

Then install esp32 and libraries etc as usual and try to compile this sketch, and it should all work.