Help with error

Hello I want to send data from uno r4 to google sheets I've only used chatgpt as my guide in coding.
Here is my code and the error:

#include <WiFiS3.h>
#include <HttpClient.h>

const char* ssid = "Wifi";
const char* password = "saymyname";
const char* serverName = "https://script.google.com/macros/s/24151/exec";

WiFiClient wifiClient;
HttpClient http(wifiClient);

void setup() {
  Serial.begin(115200);
  delay(1000);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");
}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {
    long timestamp = millis();
    int randomValue = random(0, 100);
    char jsonString[64];
    snprintf(jsonString, sizeof(jsonString), "{\"timestamp\":%ld,\"randomValue\":%d}", timestamp, randomValue);

    if (http.post(serverName, "application/json", jsonString)) {
      int httpResponseCode = http.responseStatusCode();
      Serial.println(httpResponseCode);
      String response;
      char c;
      while (http.available()) {
        c = http.read();
        response += c;
      }
      Serial.println(response);
    } else {
      Serial.println("Failed to send HTTP POST request");
    }
  } else {
    Serial.println("WiFi Disconnected");
  }
  delay(60000);
}

Serial Monitor Output:

  addr: 20007ee0    data: 00000000
  addr: 20007ee4    data: 0000b9a7
  addr: 20007ee8    data: 00012e5d
  addr: 20007eec    data: 00005c0b
  addr: 20007ef0    data: 00012e5d
  addr: 20007ef4    data: 00008eaf
  addr: 20007ef8    data: 00008ea5
  addr: 20007efc    data: 00002599
====================================
=================== Registers information ====================
  R0 : 2c636578  R1 : 00011e6f  R2 : 00000000  R3 : 200003ac
  R12: 20007cfb  LR : 00004995  PC : 0000aec2  PSR: 41000000
==============================================================
Bus fault is caused by precise data access violation
The bus fault occurred address is 2c636578
Show more call stack info by run: addr2line -e "C:\Users\414\AppData\Local\Temp\arduino\sketches\7576C90811A68C6813F95B3D5B0A277C/sketch_may28a.ino".elf -a -f 0000aec2 00004994 000051da 0000fb5e 00005a78 00004e0c 0000f880 000041d6 0000aeb6 0000af34 0000b968 0000b9a6 00005c0a 00008eae 00008ea4

Can someone help me with this one I am not particularly great at doing this. Any help would be appreciated.

As your topic does not relate directly to the installation or operation of the IDE it has been moved to the Programming Questions category of the forum

Sorry for the wrong tag

How did you set up your google sheets?

Hi @newbieeee23241. I tried running your sketch on my UNO R4 WiFi board to see if I could identify the source of the crash, but unfortunately was not able to reproduce the crash so I didn't get anywhere with that.

So my recommendation is for you to try the suggestion that was provided with the stack trace:

Hopefully that will identify the specific code that is causing the crash.

I'll provide instructions you can follow to do that:

  1. Right click the Windows "Start" button.
    A context menu will open.
  2. Select "Search" from the context menu.
    The Windows "Start" menu will open with a search field selected.
  3. Type windows powershell ise in the search field.
  4. Select "Windows PowerShell ISE" from the search results.
    A "Windows PowerShell ISE" window will open.
  5. Type the following command:
    & "$Env:LOCALAPPDATA\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line" -e "C:\Users\414\AppData\Local\Temp\arduino\sketches\7576C90811A68C6813F95B3D5B0A277C/sketch_may28a.ino.elf" -a -f 0000aec2 00004994 000051da 0000fb5e 00005a78 00004e0c 0000f880 000041d6 0000aeb6 0000af34 0000b968 0000b9a6 00005c0a 00008eae 00008ea4
    
  6. Press the Enter key.

You should now see a list of file paths and line numbers in the sketch program's source code files correlating to each of the addresses in the stack trace produced by the crash.

For example, this output:

0x0000410c
loop
C:\Users\per\Documents\Arduino\Foo\Foo.ino:42

Would tell me that the source code for address 0x0000410c in the stack trace is at line 42 in the file C:\Users\per\Documents\Arduino\Foo\Foo.ino.


:exclamation: You will typically see some strange paths not present on your computer in the later part of the tool's output. These are from addresses in the files of the board's core that were precompiled by the developers of the platform. It is unlikely the crash is caused by that code so you can simply ignore that part of the output.


If you check the code at the lines in the tool output, and the context of those lines, you might be able to identify the problem in the code that caused the crash.

If not, or if you do identify the problem but aren't sure about how to solve it, you can share the tool output here and the forum helpers will try to assist. I'll provide instructions you can follow to share the tool output:

  1. Switch back to the PowerShell window.
  2. Press the Ctrl+Shift+A keyboard shortcut.
    This will select all the text in the PowerShell window.
  3. Press the Ctrl+C keyboard shortcut.
    This will copy the contents of the PowerShell window to the clipboard.
  4. Open a forum reply here by clicking the "Reply" button.
  5. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  6. Press the Ctrl+V keyboard shortcut.
    This will paste the output into the code block.
  7. Move the cursor outside of the code block markup before you add any additional text to your reply.
  8. Click the "Reply" button to post the output.
function doPost(e) {
  // Check if e.postData is defined
  if (e && e.postData) {
    // Access the active sheet
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    
    // Parse the JSON data from the POST request
    var jsonData = JSON.parse(e.postData.contents);
    
    // Check if jsonData contains the expected properties
    if (jsonData && jsonData.timestamp && jsonData.value1 && jsonData.value2) {
      // Extract data from JSON
      var timestamp = jsonData.timestamp;
      var value1 = jsonData.value1;
      var value2 = jsonData.value2;
      
      // Append the data to the sheet
      sheet.appendRow([timestamp, value1, value2]);
      
      // Return a success message
      return ContentService.createTextOutput("Data received successfully");
    } else {
      // Return an error message if jsonData is incomplete
      return ContentService.createTextOutput("Error: Incomplete JSON data");
    }
  } else {
    // Return an error message if e.postData is undefined
    return ContentService.createTextOutput("Error: Missing POST data");
  }
}

I just followed chatgpt's advise

sorry for the late reply sir as I was busy today I tried to follow your instructions and here is how it went.

PS C:\Users\nadel> & "$Env:LOCALAPPDATA\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line" -e "C:\Users\414\AppData\Local\Temp\arduino\sketches\7576C90811A68C6813F95B3D5B0A277C/sketch_may28a.ino.elf" -a -f 0000aec2 00004994 000051da 0000fb5e 00005a78 00004e0c 0000f880 000041d6 0000aeb6 0000af34 0000b968 0000b9a6 00005c0a 00008eae 00008ea4
C:\Users\nadel\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line.exe: 'C:\Users\414\AppData\Local\Temp\arduino\sketches\7576C90811A68C6813F95B3D5B0A277C/sketch_may28a.ino.elf': No such file

I notice that the username on your computer is nadel:

but the username shown in the .elf file path in the stack trace is 414:

The .elf file is generated when you compile the sketch program that is running on the UNO R4 WiFi board and generating the fault. So the .elf file is present on the computer and user account that was used to compile and upload the sketch, and thus you must also run the addr2line command on the computer and user account that was used to compile the sketch.

If you are using a different computer or user account now than you were when you uploaded the sketch to your board, you can simply generate a new .elf file by uploading the sketch to your board again:

  1. Connect the UNO R4 WiFi board to your computer with a USB cable.
  2. Open your Google Sheets sketch in Arduino IDE.
  3. Select the UNO R4 WiFi board in Arduino IDE.
  4. Select Sketch > Upload from the Arduino IDE menus.
  5. Wait for the upload to finish successfully.
  6. Open the Arduino IDE Serial Monitor.
  7. Wait for the stack trace to be printed in Serial Monitor.
  8. Repeat the instructions I provided in my previous reply, except this time replace the C:\Users\414\AppData\Local\Temp\arduino\sketches\7576C90811A68C6813F95B3D5B0A277C/sketch_may28a.ino.elf path in the command from step (5) of those instructions with the path that is shown in the new stack trace.

Hopefully this time the command will produce the expected output. If not, let us know and we'll try to figure out what is going wrong.

That doesn't answer anything, I don't know what guidelines chatGPT gives.
I was asking about setup in google sheets, not your arduino code.
You don't have valid script address from google.

This is a real bad choice. Especcially jumping between chatGPT and real humans.
The reason is that chatGPT will modify your code in a way that humans can't follow.

So you have to make a fundamental decision:
using 100% = always chatGPT

OR

modifying your code 100% = always by humans.

any kind of mixing it will end up in confusion.


This was the output Sir. Please don't worry for this project anymore. I already found another solution which is to send data to the google firebase then to google sheets. I really appreciate your help and time for this one. Thanks and have a good day!

You posted some irrelevant parts of the forum post into PowerShell.

Congratulations on finding a solution! Thank you for taking the time to post an update.

You are welcome.

Regards,
Per

Sorry again sir I'm really a newbie in coding as I was also pressed on time I haven't tried to learn this and only used chatgpt as my guide. Thank you again and enjoy your day.

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