Skip to content

Error: Expected ')' before numeric constant #6247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
VOMediola opened this issue Feb 7, 2022 · 10 comments · Fixed by #6659
Closed
1 task done

Error: Expected ')' before numeric constant #6247

VOMediola opened this issue Feb 7, 2022 · 10 comments · Fixed by #6659
Assignees
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved
Milestone

Comments

@VOMediola
Copy link

Board

esp32

Device Description

n/a

Hardware Configuration

n/a

Version

latest master

IDE Name

esp-idf v4.4

Operating System

linux

Flash frequency

40

PSRAM enabled

no

Upload speed

115200

Description

I have the same issue as described here microsoft/azure-iot-developer-kit#169 when trying to use Arduino core in https://github.com/project-chip/connectedhomeip/.

Solution is the same - replace
const IPAddress INADDR_NONE(0,0,0,0);
with
const IPAddress IP_ADDR_NONE(0,0,0,0);

in cores\arduino\IPAddress.h

Sketch

..

Debug Message

..

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@VOMediola VOMediola added the Status: Awaiting triage Issue is waiting for triage label Feb 7, 2022
@SuGlider SuGlider self-assigned this Feb 10, 2022
@SuGlider SuGlider added Status: In Progress ⚠️ Issue is in progress and removed Status: Awaiting triage Issue is waiting for triage labels Mar 4, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Mar 4, 2022

@VOMediola
Could you please point to the application you have tried to build that caused such issue?
Are there instructions on how to build it?
I'll investigate this issue.
Thanks.

@VojtechBartoska
Copy link
Contributor

any updates @VOMediola ?

@Sys64736
Copy link

Sys64736 commented Apr 18, 2022

I've also had this compile error before. Changing the const IPAddress as stated above does get rid of the error and let's the compile finish.

|-- <FS> 2.0.0
|-- <ESP8266 and ESP32 OLED driver for SSD1306 displays> 4.2.1
|   |-- <Wire> 2.0.0
|   |-- <SPI> 2.0.0
|-- <ArduinoJson> 6.19.3+sha.7abf875
|-- <DNSServer> 2.0.0
|   |-- <WiFi> 2.0.0
|-- <HTTPClient> 2.0.0
|   |-- <WiFi> 2.0.0
|   |-- <WiFiClientSecure> 2.0.0
|   |   |-- <WiFi> 2.0.0
|-- <WebServer> 2.0.0
|   |-- <WiFi> 2.0.0
|   |-- <FS> 2.0.0
|-- <WebSockets> 2.3.6+sha.28ed615
|   |-- <Ethernet> 2.0.0
|   |   |-- <WiFi> 2.0.0
|   |-- <SPI> 2.0.0
|   |-- <WiFi> 2.0.0
|   |-- <WiFiClientSecure> 2.0.0
|   |   |-- <WiFi> 2.0.0
|-- <WiFiClientSecure> 2.0.0
|   |-- <WiFi> 2.0.0
|-- <Wire> 2.0.0
Building in release mode
Compiling C:\.pio\build\esp32c3\src\OTA.cpp.o
Compiling C:\.pio\build\esp32c3\src\main.cpp.o
Generating partitions C:\.pio\build\esp32c3\partitions.bin
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFi.cpp.o
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFiAP.cpp.o
In file included from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/lwip/lwip/src/include/lwip/ip_addr.h:43,
                 from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/tcpip_adapter/include/tcpip_adapter_types.h:18,
                 from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/tcpip_adapter/include/tcpip_adapter.h:24,
                 from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/esp_netif/include/esp_netif.h:35,
                 from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/esp_event/include/esp_event_legacy.h:22,
                 from C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/esp_event/include/esp_event.h:28,
                 from src/OTA.cpp:5:
C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/lwip/lwip/src/include/lwip/ip4_addr.h:63:37: error: expected ')' before numeric constant        
 #define IPADDR_NONE         ((u32_t)0xffffffffUL)
                             ~       ^~~~~~~~~~~~
C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32c3/include/lwip/lwip/src/include/lwip/inet.h:71:29: note: in expansion of macro 'IPADDR_NONE'
 #define INADDR_NONE         IPADDR_NONE
                             ^~~~~~~~~~~
C:/Users/Mark/.platformio/packages/framework-arduinoespressif32/cores/esp32/IPAddress.h:94:17: note: in expansion of macro 'INADDR_NONE'
 const IPAddress INADDR_NONE(0, 0, 0, 0);
                 ^~~~~~~~~~~
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFiClient.cpp.o
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFiGeneric.cpp.o
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFiMulti.cpp.o
Compiling C:\.pio\build\esp32c3\libc0e\WiFi\WiFiSTA.cpp.o
*** [C:\.pio\build\esp32c3\src\OTA.cpp.o] Error 1

That's with: 2.02 and ½ ;)
HEAD is now at 3f79097 Add Preferences library API and tutorial documents (#6442)
Tool Manager: framework-arduinoespressif32 @ 0.0.0+sha.3f79097d has been installed!

These are the includes from the OTA file and I think one of them, or a dependency of one, has a conflict with const IPAddress INADDR_NONE(0,0,0,0).

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_event.h"
#include "esp_log.h"
#include "esp_ota_ops.h"
#include "esp_http_client.h"
#include "esp_flash_partitions.h"
#include "esp_partition.h"
#include "nvs.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "errno.h"

@SuGlider
Copy link
Collaborator

This issue is linked to the issue described in #6610

@SuGlider
Copy link
Collaborator

We are currently working on a definitive solution.

@SuGlider SuGlider moved this from Todo to In Progress in Arduino ESP32 Core Project Roadmap Apr 21, 2022
@SuGlider SuGlider added this to the 2.0.3 milestone Apr 21, 2022
@SuGlider SuGlider added Area: BT&Wifi BT & Wifi related issues Status: In Progress ⚠️ Issue is in progress and removed Status: Pending Resolution: Awaiting response Waiting for response of author labels Apr 21, 2022
@SuGlider
Copy link
Collaborator

SuGlider commented Apr 22, 2022

@Sys64736 @VOMediola

The main issue is that <lwip/inet.h> declares #define INADDR_NONE IPADDR_NONE and it includes <lwip/ip4_addr.h> that declares #define IPADDR_NONE ((u32_t)0xffffffffUL) (IP 255.255.255.255)

When <lwip/inet.h> is included, it makes the Arduino declaration of "IPAddress INADDR_NONE(0,0,0,0)" invalid, causing a potential compilation error depending on the #include order, amonf other issues.

@SuGlider
Copy link
Collaborator

We are currently working on a solution for it.

Repository owner moved this from In Progress to Done in Arduino ESP32 Core Project Roadmap Apr 29, 2022
me-no-dev pushed a commit that referenced this issue Apr 29, 2022
Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for #6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes #6610
fixes #6247
fixes #4732
Jason2866 added a commit to tasmota/arduino-esp32 that referenced this issue Apr 29, 2022
Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for espressif#6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes espressif#6610
fixes espressif#6247
fixes espressif#4732

Co-authored-by: Rodrigo Garcia <[email protected]>
Jason2866 added a commit to tasmota/arduino-esp32 that referenced this issue Aug 11, 2022
* Tasmota changes

* Fixes INADDR_NONE  (espressif#6659) (#136)

Description of Change

Fixes IPAddress INADDR_NONE declaration when using Arduino WiFi or ETH.
This symbol was defined as 0xffffffff by lwip /inet.h, making it impossible to use INADDR_NONE correctly.

This PR only works when <wifi-provisioning/wifi_config.h> has a modification to include <lwip/ip4_addr.h> instead of <lwip/inet.h>. This will be done directly to the sdk folder in the github structure and it has been fixed in IDF by a separated Merge Request. This will be reflected in the future, for good.

Tests scenarios

This PR was tested with all Arduino WiFi examples, including AsyncUDP. Also with ETH examples.
It was also tested for espressif#6610 test cases.
Testing done for ESP32, ESP32-S2, ESP32-C3 and ESP32-S3.

Related links

fixes espressif#6610
fixes espressif#6247
fixes espressif#4732

Co-authored-by: Rodrigo Garcia <[email protected]>

* Update README.md

Co-authored-by: Rodrigo Garcia <[email protected]>
@havrak
Copy link

havrak commented Nov 24, 2023

Issue persist with idf 5.1.2 and 3.0.0 alpha2 build of Arduino esp. Declarations of INADDR_NONE between cores/esp32/IPAddress.h and components/lwip/lwip/src/include/lwip/inet.h are in conflict.

@Plashu
Copy link

Plashu commented Jan 9, 2024

Just upgraded to 5.1.2 and just like with the previous version, compilation fails unless you comment out the line:
#define IPADDR_NONE ((u32_t)0xffffffffUL) in "ip4_addr.h"
I think it conflicts with declaration: IPAddress INADDR_NONE(0, 0, 0, 0); in "IPAddress.cpp"
via #define INADDR_NONE IPADDR_NONE in "inet.h"
It probably depends on the include order of these three files.

@crossplatformdev
Copy link

This sketch produces the error.

#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "nvs_flash.h"
#include "driver/gpio.h"
#include "driver/adc.h"
#include "esp_adc/adc_continuous.h"
#include "lwip/sockets.h"
#include "esp_log.h"
#include "Arduino.h"
#include "soc/soc_caps.h"

#define CAPTURE_DEPTH 1472
#define CAPTURE_CHANNEL GPIO_NUM_35  // GPIO35, ADC1 channel 7
#define WIFI_SSID "sdr"
#define WIFI_PASS "sdr12345"
#define MAX_STORE_BUF_SIZE (CAPTURE_DEPTH * 2)

uint8_t data_dma;
bool data_val;
bool streaming;
adc_continuous_handle_t adc_handle;
static struct sockaddr_in dest_addr;
static int udp_sock;
static pthread_t adc_thread;
static pthread_t led_thread;
static timer_t led_timer;

static void udp_send_data(uint8_t *data, size_t len) {
    sendto(udp_sock, data, len, 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
}

static bool adc_continuous_callback(adc_continuous_handle_t handle, const adc_continuous_evt_data_t *edata, void *user_data) {
    if (streaming && edata->size > 0) {
        udp_send_data(edata->conv_frame_buffer, edata->size);
        data_val = false;
    }
    return false;  // No need to wake any high priority task
}

static void* adc_continuous_task(void *arg) {
    uint8_t result[CAPTURE_DEPTH];
    uint32_t read_len = 0;
    while (1) {
        esp_err_t ret = adc_continuous_read(adc_handle, result, CAPTURE_DEPTH, &read_len, ADC_MAX_DELAY);
        if (ret == ESP_OK && streaming && read_len > 0) {
            udp_send_data(result, read_len);
            data_val = false;
        }
        usleep(10000);  // Sleep to prevent busy-waiting
    }
    return NULL;
}

static void start_stream() {
    if (streaming) return;

    data_dma = 0;
    data_val = false;
    streaming = true;

    adc_continuous_start(adc_handle);
}

static void stop_stream() {
    if (!streaming) return;

    adc_continuous_stop(adc_handle);
    streaming = false;
}

static void led_timer_callback(union sigval sigval) {
    int status = gpio_get_level(GPIO_NUM_2);
    gpio_set_level(GPIO_NUM_2, !status);
}

static void* led_timer_task(void *arg) {
    struct sigevent sev;
    struct itimerspec its;
    timer_t *timerid = (timer_t *)arg;
    
    sev.sigev_notify = SIGEV_THREAD;
    sev.sigev_notify_function = led_timer_callback;
    sev.sigev_notify_attributes = NULL;
    sev.sigev_value.sival_ptr = NULL;
    
    timer_create(CLOCK_REALTIME, &sev, timerid);
    
    its.it_value.tv_sec = 0;
    its.it_value.tv_nsec = 250 * 1000000; // 250 ms
    its.it_interval.tv_sec = 0;
    its.it_interval.tv_nsec = 250 * 1000000; // 250 ms
    timer_settime(*timerid, 0, &its, NULL);
    
    while (1) {
        pause(); // Wait for the timer to call the callback
    }
    return NULL;
}

static void init_network() {
    // Initialize the TCP/IP stack (replaced tcpip_adapter_init with esp_netif_init)
    esp_netif_init();
    esp_event_loop_create_default();
    esp_netif_create_default_wifi_sta();  // Create default Wi-Fi STA netif

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    esp_wifi_init(&cfg);
    esp_wifi_set_mode(WIFI_MODE_STA);
    esp_wifi_start();

    // Set up connection information
    wifi_config_t sta_config = {
        .sta = {
            .ssid = WIFI_SSID,
            .password = WIFI_PASS,
            .scan_method = WIFI_FAST_SCAN,
            .sort_method = WIFI_CONNECT_AP_BY_SIGNAL            
        }
    };

    // Use WIFI_IF_STA instead of ESP_IF_WIFI_STA
    esp_wifi_set_config(WIFI_IF_STA, &sta_config);
    esp_err_t error = esp_wifi_connect();
    
    if(error == ESP_OK) {
        Serial.println("Connected to Wi-Fi");
    } else {
        Serial.printf("Failed to connect to Wi-Fi: %d\n", error);
    }

    // Initialize UDP socket
    udp_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
    memset(&dest_addr, 0, sizeof(dest_addr));
    dest_addr.sin_family = AF_INET;
    dest_addr.sin_port = htons(7778);
    inet_pton(AF_INET, "192.168.1.82", &dest_addr.sin_addr);
}

static void init_adc_dma() {
    adc_continuous_handle_cfg_t adc_handle_cfg = {
        .max_store_buf_size = MAX_STORE_BUF_SIZE,
        .conv_frame_size = CAPTURE_DEPTH,
    };

    // Create the ADC continuous handle
    Serial.println(" - Creating ADC continuous handle...");
    ESP_ERROR_CHECK(adc_continuous_new_handle(&adc_handle_cfg, &adc_handle));

    // ADC continuous mode configuration
    adc_digi_pattern_config_t adc_pattern = {
        .atten = ADC_ATTEN_DB_12,
        .channel = ADC1_CHANNEL_7,
        .unit = ADC_UNIT_1,
        .bit_width = ADC_WIDTH_BIT_12
    };

    adc_continuous_config_t adc_config = {
        .pattern_num = 1,
        .adc_pattern = &adc_pattern,
        .sample_freq_hz = 22000, // 22kHz sampling frequency
        .conv_mode = ADC_CONV_SINGLE_UNIT_1,
        .format = ADC_DIGI_OUTPUT_FORMAT_TYPE1
    };
    Serial.println(" - Configuring ADC continuous mode...");
    ESP_ERROR_CHECK(adc_continuous_config(adc_handle, &adc_config));

    // Register callbacks for ADC events
    adc_continuous_evt_cbs_t cbs = {
        .on_conv_done = adc_continuous_callback,
        .on_pool_ovf = NULL
    };
    Serial.println(" - Registering ADC continuous event callbacks...");
    ESP_ERROR_CHECK(adc_continuous_register_event_callbacks(adc_handle, &cbs, NULL));

    // Create task for handling ADC continuous readings
    Serial.println(" - Creating ADC continuous task...");
    pthread_create(&adc_thread, NULL, adc_continuous_task, NULL);
    Serial.println("ADC continuous task started");
}

void setup() {
    // Initialize NVS (required for Wi-Fi)
    Serial.begin(115200);
    Serial.println("Initializing NVS...");
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);

    // Initialize GPIO for LED (replaced gpio_pad_select_gpio with gpio_reset_pin)
    Serial.println("Initializing GPIO...");
    gpio_reset_pin(GPIO_NUM_2);
    gpio_set_direction(GPIO_NUM_2, GPIO_MODE_OUTPUT);

    // Initialize network
    Serial.println("Initializing network...");
    init_network();

    // Initialize ADC with DMA
    Serial.println("Initializing ADC with DMA...");
    init_adc_dma();

    // Start LED blinking
    Serial.println("Starting LED blinking...");
    pthread_create(&led_thread, NULL, led_timer_task, &led_timer);

    // Start stream
    Serial.println("Starting stream...");
    start_stream();

    // Serial output
    Serial.println("Initialization complete. Starting main loop...\n");
}

void loop() {
    // Replace vTaskDelay with sleep for main loop
    sleep(1);
    Serial.println("Looping...");

    char c = Serial.read();
    if ('s' == c) {
        start_stream();
    } else if ('x' == c) {
        stop_stream();
    }

    if('q' == c) {
        Serial.println("Quitting...");
        stop_stream();
        sleep(1);
        esp_wifi_disconnect();
        esp_wifi_stop();
        sleep(1);
        esp_wifi_deinit();
        sleep(1);
        if (adc_thread) {
            pthread_cancel(adc_thread);
            pthread_join(adc_thread, NULL);
        }
    }
}

The solution has been addressed here:
#4405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: BT&Wifi BT & Wifi related issues Status: Solved
Projects
Development

Successfully merging a pull request may close this issue.

7 participants