Inability to Reach the Server


In this project, I am recording sound from the ESP32 Wroom model and INMP441 microphone model, recording it and sending the sound file to the server, but it does not connect to the server. I am using Railway as a server

I moved your topic to a more appropriate forum category @Codinho_R10 .

The Nano ESP32 category you chose is only used for discussions directly related to the Arduino Nano ESP32 board.

In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

Welcome to the forum Codinho_R10.

It might be worth trying the ESP Exception decoder to pinpoint the problem in your code:

It would, of course, also be helpful if you could post the said code, ensuring to enclose it in CODE tags. Its rather difficult for anyone to pinpoint the problem without it..... :slight_smile:

Could you also explain and post a link to "Railway" server? I did find railway.app. Is that what you are referring to here? I didn't find anything else relevant while Googling. I expect that there will be an API handler of some sort, but since the MCU is throwing an exception, I don't think API handling is going to be the problem here, but something a bit more fundamental such as a buffer overrun perhaps or some other memory handling issue.

Code Construction is generally as follows;


  #include <WiFi.h>
  #include <HTTPClient.h>
  #include <driver/i2s.h>
  #include <base64.h>
  
  #define I2S_WS 33
  #define I2S_SD 32
  #define I2S_SCK 25
  #define I2S_PORT I2S_NUM_0
  #define bufferLen 512

  int16_t sBuffer[bufferLen];

  const char* ssid = "******";
  const char* password = "******";
  const char* serveUrl = "https://flask-production-10.up.railway.app/upload";


  unsigned long recordingDuration = 5000;
  unsigned long lastRecordingTime = 0;
  bool isRecording = false;

  void i2s_install() {
      const i2s_config_t i2s_config = {
      .mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
      .sample_rate = 44100,
      .bits_per_sample = i2s_bits_per_sample_t(16),
      .channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
      .communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_STAND_I2S),
      .intr_alloc_flags = 0,
      .dma_buf_count = 16,
      .dma_buf_len = 1024,
      .use_apll = false
    };
      esp_err_t err;
      err = i2s_driver_install(I2S_PORT, &i2s_config, 0, NULL);
      if (err != ESP_OK) {
      Serial.print("I2S driver yükleme hatası: ");
      Serial.println(esp_err_to_name(err));
      return;
    }
  }


  void i2s_setpin() {
    const i2s_pin_config_t pin_config = {
      .bck_io_num = I2S_SCK,
      .ws_io_num = I2S_WS,
      .data_out_num = -1,
      .data_in_num = I2S_SD
    };
    esp_err_t err = i2s_set_pin(I2S_PORT, &pin_config);
    if (err != ESP_OK) {
      Serial.print("I2S pin ayarı hatası: ");
      Serial.println(esp_err_to_name(err));
      return;
    }
  }

  void connectToWiFi() {
    WiFi.begin(ssid, password);
    int retryCount = 0;

    while (WiFi.status() != WL_CONNECTED && retryCount < 5) {
        delay(2000);
        Serial.println("Wi-Fi yeniden baglaniyor...");
        retryCount++;
    }
    if (WiFi.status() == WL_CONNECTED) {
        Serial.println("WiFi baglandi.");
        Serial.println(WiFi.localIP());
    } else {
        Serial.println("WiFi baglantisi basarisiz. Cihaz yeniden baslatiliyor...");
        ESP.restart();
    }
  }

  void setup() {
    Serial.begin(115200);
    connectToWiFi();
    i2s_install();
    i2s_setpin();
    delay(500);
  }

  void loop() {
    const int bufferSize = 512;
    int16_t i2sData[bufferSize];
    size_t bytesRead;
    unsigned long currentMillis = millis();

    if (currentMillis - lastRecordingTime >= recordingDuration && !isRecording) {
        isRecording = true;
        Serial.println("Ses kaydı başlatılıyor.");
        lastRecordingTime = currentMillis;
    }   
    if (isRecording){
      size_t bytesIn = 0;
      esp_err_t result = i2s_read(I2S_PORT, &sBuffer, bufferLen, &bytesIn, portMAX_DELAY);
      if (result != ESP_OK) {
        Serial.print("I2S okuma hatası: ");
        Serial.println(esp_err_to_name(result));
      }
      if (result == ESP_OK && bytesIn > 0) {
            HTTPClient http;
            http.begin(serveUrl);
            http.addHeader("Content-Type", "application/octet-stream");
         
            WiFiClient * client = http.getStreamPtr();
            client->write((uint8_t*)sBuffer, bytesIn);

            int httpResponseCode = http.POST("");

            if (httpResponseCode > 0) {
                Serial.println("API'ye veri gönderildi.");
                Serial.printf("API Yanıt Kodu: %d\n", httpResponseCode);
            } else {
                Serial.printf("HTTP Hatasi: %s\n", http.errorToString(httpResponseCode).c_str());
            }
            http.end();
        } else {
            Serial.println("I2S verisi okunamadı!");
        }
    }
    delay(1000);
  }

And I am using Railway.app as the Server, so:https://railway.app

When I installed and tried the application in the link you sent me, the response I received was as follows:

PC: 0x400d2b1e
EXCVADDR: 0x00000000
Decoding stack results
0x400d2b1b: loop() at C:\Users\user\OneDrive\Belgeler\Arduino\sketch_dec12a/sketch_dec12a.ino line 107
0x400db000: loopTask(void)* at C:\Users\user\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.1.0-RC3\cores\esp32*main.cpp* line 74
0x4008eebe: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c line 139

Ok, so what do you have in line 106 and 107 of your sketch_dec12a.ino? Is it exactly the same as what is posted above?

A call to something in line 107 (or possibly 106) is causing the exception.

Thank you for your help. I solved my problem. As you said, the error on line 107 is WiFiClient * client = http.getStreamPtr(); Now I can generally communicate with the server and perform post processing.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.