Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - Ed

Pages: 1
1
TinyDuino Processors & TinyShields / WiFi Shield Upload Crash
« on: July 02, 2023, 05:42:17 PM »
Hi, I'm new to Arduino in general and am doing my first project with a Tinyzero and the WiFi and GPS shields. I'm facing an issue I don't seem to be able to work out and was hoping for some advice.

Part of my program uploads data via the WiFi module to a HTTP endpoint. As it's just a single request that gets repeated I decided to try and code it manually using only WiFi101 and not including an additional HTTP library.

The amount of data I upload varies as there's a buffer for when it's not connected. It seems that when I upload just one line (< 100 characters not including HTTP headers) it works fine however if I upload say 5 lines (~ 400 characters not including HTTP headers) it'll crash. I've got a loop which calculates the length of the content, some "wificlient.println()" to send the headers and then a loop with several more "wificlient.println()" which prints the data in JSON format until I've sent everything in the buffer.

It seems after about 3-5 of these lines being printed to WiFi the system will crash, if it's sending fewer it all works fine. When it crashes I get no more serial output, the green LED on the main board flashes on and off and both LEDs on the WiFi shield stay on. Waiting for 10 minutes makes no difference.

Is there any way to tell from those LEDs what might have happened? Am I doing this in a really rubbish way? Any help would be very much appreciated!


Code: [Select]
  if (wificlient.connect(server, 80)) {
    SerialUSB.println("Connected to HTTP");

    // Count the length of the content first for the HTTP request
    long contentLength = 9; // "jsonGPS=["
    for (int i = 0; i < GPSBuffer_next; i++) {
      if (i != 0) {
        contentLength++;  // ","
      }
      contentLength += 8; // "{\"time\":"
      contentLength += String(GPSBuffer[i].time).length();
      contentLength += 7;  // ",\"lat\":"
      contentLength += String(GPSBuffer[i].lat, 6).length();
      contentLength += 7;  // ",\"lon\":"
      contentLength += String(GPSBuffer[i].lon, 6).length();
      contentLength += 7;  // ",\"alt\":"
      contentLength += String(GPSBuffer[i].alt, 6).length();
      contentLength++;  // "}"
    }
    contentLength++;  // "]"

    SerialUSB.print("Sending request with content length: ");
    SerialUSB.println(contentLength);

    wificlient.print("POST ");
    wificlient.print(serverRequestPath);
    wificlient.println(" HTTP/1.1");
    wificlient.print("Host: ");
    wificlient.println(server);
    wificlient.println("User-Agent: Something/1.1");
    wificlient.println("Content-Type: application/x-www-form-urlencoded");
    wificlient.print("Content-Length: ");
    wificlient.println(contentLength);
    wificlient.println();
    SerialUSB.println("-Sent Headers");
    SerialUSB.println("Sending content...");
   
    // Headers done, send the data
    // Format is [{"time":5, "lat":6, "lon":7, "alt":8},...]
    wificlient.print("jsonGPS=[");
    for (int i = 0; i < GPSBuffer_next; i++) {
      SerialUSB.print(i);
      if (i != 0) {
        wificlient.print(",");
      }
      wificlient.print("{\"time\":");
      wificlient.print(GPSBuffer[i].time);
      wificlient.print(",\"lat\":");
      wificlient.print(GPSBuffer[i].lat, 6);
      wificlient.print(",\"lon\":");
      wificlient.print(GPSBuffer[i].lon, 6);
      wificlient.print(",\"alt\":");
      wificlient.print(GPSBuffer[i].alt, 6);
      wificlient.print("}");
    }
    wificlient.print("]");
    SerialUSB.println();
    SerialUSB.println("Sent Request");

Pages: 1
SMF spam blocked by CleanTalk