TheRealWaldo / AMG8833-ESPHOME

24 stars 5 forks source link

Syntax error in amg8833_person_detected.h #14

Open UniKyrn opened 1 year ago

UniKyrn commented 1 year ago

I'm using the latest code here and an up to date ESPHome. If I include the header for person detection, it throws a syntax error. Perhaps a newer version of the Sparkfun Library has changed the function definition? If I comment that include out, the rest of the example works fine as long as I don't include the PD sensor.

Thermal Camera Controls Thermal Camera Display

INFO ESPHome 2023.5.5 INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: platformio/espressif8266@3.2.0)

HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash Dependency Graph |-- ESPAsyncTCP-esphome @ 1.2.3 |-- Wire @ 1.0 |-- SparkFun GridEYE AMG88 Library @ 1.0.2 |-- ESPAsyncWebServer-esphome @ 2.1.0 | |-- ESPAsyncTCP-esphome @ 1.2.3 | |-- Hash @ 1.0 | |-- ESP8266WiFi @ 1.0 |-- DNSServer @ 1.1.1 |-- ESP8266WiFi @ 1.0 |-- ESP8266mDNS @ 1.2 |-- AsyncMqttClient-esphome @ 0.8.6 | |-- ESPAsyncTCP-esphome @ 1.2.3 |-- ArduinoJson @ 6.18.5 Compiling /data/esp8266-thermal-camera/.pioenvs/esp8266-thermal-camera/src/main.cpp.o In file included from src/main.cpp:68: src/amg8833_person_detected.h:5:1: error: expected class-name before '{' token 5 | { | ^ src/amg8833_person_detected.h: In member function 'virtual void AMG8833PersonDetectedComponent::update()': src/amg8833_person_detected.h:46:17: error: 'publish_state' was not declared in this scope; did you mean 'last_state'? 46 | publish_state(true); | ^~~~~ | last_state src/amg8833_person_detected.h:58:21: error: 'publish_state' was not declared in this scope; did you mean 'last_state'? 58 | publish_state(false); | ^~~~~ | last_state *** [/data/esp8266-thermal-camera/.pioenvs/esp8266-thermal-camera/src/main.cpp.o] Error 1 ========================= [FAILED] Took 12.92 seconds =========================

TheRealWaldo commented 1 year ago

publish_state is from the ESPHome library, so ESPHome has likely introduced a breaking change. Unfortunately, their versioning makes figuring out which version introduces breaking changes difficult, so you might have to guess and roll back a few versions to get it to build.

TheRealWaldo commented 1 year ago

That said, the error message seems to indicate that there is something else wrong with the code in that file. Can you post the contents of your amg8833_person_detected.h?

TheRealWaldo commented 1 year ago

Also, how are you including it?

UniKyrn commented 1 year ago

I'm including it per your amg833.yaml example, as follows: (the odd path is because I put the ZIP file of the repository in the esphome directory for reference)

substitutions:
  name: esp8266-thermal-camera
  text_name: "ESP8266 Thermal Camera"

esphome:
  name: ${name}
  comment: WeMos D1 Mini
  platform: esp8266
  board: esp01_1m
  name_add_mac_suffix: false
  includes:
    - ./esp8266-amg8833-github/amg8833.h
    - ./esp8266-amg8833-github/amg8833_camera.h
#    - ./esp8266-amg8833-github/amg8833_person_detected.h
  libraries:
    - "Wire"
    - "SparkFun GridEYE AMG88 Library"

Here is the actual file as I downloaded it yesterday:

#include "esphome.h"
#include <SparkFun_GridEYE_Arduino_Library.h>

class AMG8833PersonDetectedComponent : public PollingComponent, public BinarySensor
{
public:
    float get_setup_priority() const override { return esphome::setup_priority::BUS; }
    AMG8833PersonDetectedComponent() : PollingComponent(100) {}

    void setup() override
    {
        Wire.begin();
        grideye.begin();
    }

    void loop() override
    {
    }

    void update() override
    {
        float pixel_temperature;
        float min = 0;
        float max = 0;
        unsigned char local_min_index = 0;
        unsigned char local_max_index = 0;

        for (unsigned char i = 0; i < total_pixels; i++)
        {
            pixel_temperature = grideye.getPixelTemperature(i);
            if (i == 0 || pixel_temperature > max)
            {
                max = pixel_temperature;
                local_max_index = i;
            }
            if (i == 0 || pixel_temperature < min)
            {
                min = pixel_temperature;
                local_min_index = i;
            }
        }
        if (max - min > 4)
        {
            if (!last_state)
            {
                publish_state(true);
                delay_count = delay;
            }
            last_state = true;
        }
        else
        {
            if (last_state)
            {
                delay_count--;
                if (delay_count <= 0)
                {
                    publish_state(false);
                    last_state = false;
                }
            }
        }
    }

protected:
    GridEYE grideye;
    static const int size = 8;
    static const int total_pixels = size * size;
    static const int delay = 50;
    int delay_count = delay;
    bool last_state = false;
};
TheRealWaldo commented 1 year ago

One thought here is that the directory structure is your problem; the libraries may not be able to find files that they expect to be in certain folders. For example:

#include "esphome.h"
#include <SparkFun_GridEYE_Arduino_Library.h>

It may not be finding esphome.h because the file is one folder up in the way that ESPHome registers these files.

UniKyrn commented 1 year ago

So the files should be in the project directory? I'd put them in a top directory because they will probably be reused for multiple projects.

I'll tinker with it and get back to you.

On Mon, Jun 26, 2023 at 3:05 PM Will Freeman @.***> wrote:

One thought here is that the directory structure is your problem; the libraries may not be able to find files that they expect to be in certain folders. For example:

include "esphome.h"

include

It may not be finding esphome.h because the file is one folder up in the way that ESPHome registers these files.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1608382138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYUDSKVZJMVQXKH6ULTXNIBS5ANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

Hummm, the other include files have the same kind of include reference though. It works for them.

When including a remote library, where is it stored locally? It sure acts like that publish_state() function isn't defined in the current version of the library I'm getting.

On Mon, Jun 26, 2023 at 5:56 PM Brian Antoine @.***> wrote:

So the files should be in the project directory? I'd put them in a top directory because they will probably be reused for multiple projects.

I'll tinker with it and get back to you.

On Mon, Jun 26, 2023 at 3:05 PM Will Freeman @.***> wrote:

One thought here is that the directory structure is your problem; the libraries may not be able to find files that they expect to be in certain folders. For example:

include "esphome.h"

include

It may not be finding esphome.h because the file is one folder up in the way that ESPHome registers these files.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1608382138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYUDSKVZJMVQXKH6ULTXNIBS5ANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

If I've found the right library source on GitHub, it looks like they updated it about 8 months ago. I can't find the actual source to the base library though so I can't double check the class definitions.

On Mon, Jun 26, 2023 at 6:10 PM Brian Antoine @.***> wrote:

Hummm, the other include files have the same kind of include reference though. It works for them.

When including a remote library, where is it stored locally? It sure acts like that publish_state() function isn't defined in the current version of the library I'm getting.

On Mon, Jun 26, 2023 at 5:56 PM Brian Antoine @.***> wrote:

So the files should be in the project directory? I'd put them in a top directory because they will probably be reused for multiple projects.

I'll tinker with it and get back to you.

On Mon, Jun 26, 2023 at 3:05 PM Will Freeman @.***> wrote:

One thought here is that the directory structure is your problem; the libraries may not be able to find files that they expect to be in certain folders. For example:

include "esphome.h"

include

It may not be finding esphome.h because the file is one folder up in the way that ESPHome registers these files.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1608382138, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYUDSKVZJMVQXKH6ULTXNIBS5ANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

TheRealWaldo commented 1 year ago

It's complaining about publish_state not being defined, which comes from the esphome library, not the sparkfun lib.

UniKyrn commented 1 year ago

Ok, I moved the files to the same directory as the project's YAML file and adjusted the includes, and the error is still there. Where are those files in your project?

It finds esphome.h, or it would complain about the file being missing, so it seems to be finding one that doesn't have publish_state() defined.

esphome: name: ${name} comment: WeMos D1 Mini platform: esp8266 board: esp01_1m name_add_mac_suffix: false includes:

[image: image.png]

On Tue, Jun 27, 2023 at 8:55 AM Will Freeman @.***> wrote:

It's complaining about publish_state not being defined, which comes from the esphome library, not the sparkfun lib.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1609801153, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYXXXMMPOBQ2HGE6EGLXNL67HANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

Just tinkering, I changed the class definition and the error about line 5 vanished. Is it possible ESPHome changed that sensor name at some point? The class definition is always the first thing the compiler hates.

class AMG8833PersonDetectedComponent : public PollingComponent //, public BinarySensor

On Tue, Jun 27, 2023 at 1:19 PM Brian Antoine @.***> wrote:

Ok, I moved the files to the same directory as the project's YAML file and adjusted the includes, and the error is still there. Where are those files in your project?

It finds esphome.h, or it would complain about the file being missing, so it seems to be finding one that doesn't have publish_state() defined.

esphome: name: ${name} comment: WeMos D1 Mini platform: esp8266 board: esp01_1m name_add_mac_suffix: false includes:

  • amg8833.h
  • amg8833_camera.h
  • amg8833_person_detected.h libraries:
  • "Wire"
  • "SparkFun GridEYE AMG88 Library"

[image: image.png]

On Tue, Jun 27, 2023 at 8:55 AM Will Freeman @.***> wrote:

It's complaining about publish_state not being defined, which comes from the esphome library, not the sparkfun lib.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1609801153, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYXXXMMPOBQ2HGE6EGLXNL67HANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

TheRealWaldo commented 1 year ago

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

UniKyrn commented 1 year ago

Not sure where you're seeing 5.5, I'm using 6.2

INFO ESPHome 2023.6.2

INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: @.***)

On Tue, Jun 27, 2023 at 4:04 PM Will Freeman @.***> wrote:

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1610333483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYS3HECUKJJ6IWK6UD3XNNRJFANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

I was probably running 5.5 when I originally submitted the bug.

I'm using the ESPHome add-on for HA, not the standalone version, if that might change anything.

On Tue, Jun 27, 2023 at 10:09 PM Brian Antoine @.***> wrote:

Not sure where you're seeing 5.5, I'm using 6.2

INFO ESPHome 2023.6.2

INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: @.***)

On Tue, Jun 27, 2023 at 4:04 PM Will Freeman @.***> wrote:

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1610333483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYS3HECUKJJ6IWK6UD3XNNRJFANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

And there is something broken in ESPHome, or my install. I can't even get the example code to compile.

https://www.esphome.io/components/binary_sensor/custom.html

In file included from src/main.cpp:66: src/MyBinarySensor.h:3:75: error: expected class-name before '{' token 3 | class MyCustomBinarySensor : public PollingComponent, public BinarySensor { | ^ src/MyBinarySensor.h: In member function 'virtual void MyCustomBinarySensor::update()': src/MyBinarySensor.h:17:5: error: 'publish_state' was not declared in this scope 17 | publish_state(state); | ^~~~~

On Tue, Jun 27, 2023 at 10:16 PM Brian Antoine @.***> wrote:

I was probably running 5.5 when I originally submitted the bug.

I'm using the ESPHome add-on for HA, not the standalone version, if that might change anything.

On Tue, Jun 27, 2023 at 10:09 PM Brian Antoine @.***> wrote:

Not sure where you're seeing 5.5, I'm using 6.2

INFO ESPHome 2023.6.2

INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: @.***)

On Tue, Jun 27, 2023 at 4:04 PM Will Freeman @.***> wrote:

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1610333483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYS3HECUKJJ6IWK6UD3XNNRJFANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

Did a "clean build files" and then looked at the files that got created in the build folder. Yep, even though I'm using a binary sensor, the files did NOT get copied to the project.

[image: image.png]

On Wed, Jun 28, 2023 at 3:49 AM Brian Antoine @.***> wrote:

And there is something broken in ESPHome, or my install. I can't even get the example code to compile.

https://www.esphome.io/components/binary_sensor/custom.html

In file included from src/main.cpp:66: src/MyBinarySensor.h:3:75: error: expected class-name before '{' token 3 | class MyCustomBinarySensor : public PollingComponent, public BinarySensor { | ^ src/MyBinarySensor.h: In member function 'virtual void MyCustomBinarySensor::update()': src/MyBinarySensor.h:17:5: error: 'publish_state' was not declared in this scope 17 | publish_state(state); | ^~~~~

On Tue, Jun 27, 2023 at 10:16 PM Brian Antoine @.***> wrote:

I was probably running 5.5 when I originally submitted the bug.

I'm using the ESPHome add-on for HA, not the standalone version, if that might change anything.

On Tue, Jun 27, 2023 at 10:09 PM Brian Antoine @.***> wrote:

Not sure where you're seeing 5.5, I'm using 6.2

INFO ESPHome 2023.6.2

INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: @.***)

On Tue, Jun 27, 2023 at 4:04 PM Will Freeman @.***> wrote:

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1610333483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYS3HECUKJJ6IWK6UD3XNNRJFANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

FYI, I submitted the bug to the ESPHome team, who closed the issue because it uses Custom Sensors, which they are moving away from. I pointed out that I was using examples from their own documentation, for what it's worth, but I doubt they care.

On Wed, Jun 28, 2023 at 4:18 AM Brian Antoine @.***> wrote:

Did a "clean build files" and then looked at the files that got created in the build folder. Yep, even though I'm using a binary sensor, the files did NOT get copied to the project.

[image: image.png]

On Wed, Jun 28, 2023 at 3:49 AM Brian Antoine @.***> wrote:

And there is something broken in ESPHome, or my install. I can't even get the example code to compile.

https://www.esphome.io/components/binary_sensor/custom.html

In file included from src/main.cpp:66: src/MyBinarySensor.h:3:75: error: expected class-name before '{' token 3 | class MyCustomBinarySensor : public PollingComponent, public BinarySensor { | ^ src/MyBinarySensor.h: In member function 'virtual void MyCustomBinarySensor::update()': src/MyBinarySensor.h:17:5: error: 'publish_state' was not declared in this scope 17 | publish_state(state); | ^~~~~

On Tue, Jun 27, 2023 at 10:16 PM Brian Antoine @.***> wrote:

I was probably running 5.5 when I originally submitted the bug.

I'm using the ESPHome add-on for HA, not the standalone version, if that might change anything.

On Tue, Jun 27, 2023 at 10:09 PM Brian Antoine @.***> wrote:

Not sure where you're seeing 5.5, I'm using 6.2

INFO ESPHome 2023.6.2

INFO Reading configuration /config/esphome/esp8266-thermal-camera.yaml... INFO Detected timezone 'America/Los_Angeles' INFO Generating C++ source... INFO Compiling app... Processing esp8266-thermal-camera (board: esp01_1m; framework: arduino; platform: @.***)

On Tue, Jun 27, 2023 at 4:04 PM Will Freeman @.***> wrote:

Regarding where they are in my project, ESPHome does some sort of linking in the background that has them completely external to the project.

It is still there, according to the docs for the latest version: https://esphome.io/api/binary__sensor_8h.html

Looking at your output, it shows ESPhome 2023.5.5, but 2023.6.2 is now the latest; perhaps a bug in 2023.5.5?

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1610333483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYS3HECUKJJ6IWK6UD3XNNRJFANCNFSM6AAAAAAZKAYOMI . You are receiving this because you authored the thread.Message ID: @.***>

UniKyrn commented 1 year ago

Ok, figured it out, now it compiles. Including the header file is not enough to get ESPHome to add the support files, the actual sensor has to be configured also. That doesn't do much going forward, given that they are dumping Custom Sensors in favor of External Sensors, but at least it works for the moment.

TheRealWaldo commented 1 year ago

@UniKyrn any documentation you can point me to about migrating to External Sensors? I haven't had to rebuild any sensors for some time but might help other people like yourselves.

UniKyrn commented 1 year ago

Sorry. All I was told was Custom Sensors were bad and External Sensors were the New Thing.

On Thu, Jun 29, 2023 at 2:32 PM Will Freeman @.***> wrote:

@UniKyrn https://github.com/UniKyrn any documentation you can point me to about migrating to External Sensors? I haven't had to rebuild any sensors for some time but might help other people like yourselves.

— Reply to this email directly, view it on GitHub https://github.com/TheRealWaldo/AMG8833-ESPHOME/issues/14#issuecomment-1613834973, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXDYQYSED7OT2IZ3RBEO5F3XNXX7FANCNFSM6AAAAAAZKAYOMI . You are receiving this because you were mentioned.Message ID: @.***>