WiFi Shield Upload Crash

Ed · 5 · 14034

Ed

  • Newbie
  • *
    • Posts: 3
    • View Profile
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");
« Last Edit: July 03, 2023, 10:50:40 AM by Ed »


Jason

  • Administrator
  • Hero Member
  • *****
    • Posts: 107
  • TinyCircuits Employee
    • View Profile
I'm not exactly sure what's going on but here are some general ideas that might change things:
  • Add delay between uploading data (just a couple ms)
  • Buffer everything you are going to send and then send it in <100 sized byte chunks, with delay between sending chunks


Ed

  • Newbie
  • *
    • Posts: 3
    • View Profile
Thanks for the help. It looks like delays don't help, it was easy to add one to the loop and values from 5-2000ms seemed to make no difference. With lots more testing it seems it's actually random when it breaks, it's after at least 1 line has been sent but sometimes it'll get to 20 and then die.

I do however have some more info which I'm struggling to work with but hopefully might help. When I don't send the HIGH, LOW pulse to the GPS module to enable it I can then send 200 lines of data without issue. If I change nothing else and do send the HIGH, LOW pulse it then fails again when sending larger amounts of data.

I had two ideas as to what that might mean but I could be missing something else. My thoughts were either lack of power or just an incompatibility between modules.

I think it would be fine if I could disable the GPS, connect to WiFi and upload and then disconnect and enable GPS however I can't get this to work. Because both modules share pin A3 if I try to send the pulse to the GPS module to turn it off then the WiFi module is receiving that on its "reset" pin and I don't seem to be able to get it to connect after that.

Is there any way to disable the GPS module via a serial message or another method? Or some way to change the pin either GPS or WiFi uses from A3?

Could it be power related? Is it likely neither the 5V USB or your 150mAh battery can provide enough current? I've tested maxLowPowerMode and lowPowerMode on WiFi and I think the GPS is by default in the low power 1hz mode?

Again any input very much appreciated!


Jason

  • Administrator
  • Hero Member
  • *****
    • Posts: 107
  • TinyCircuits Employee
    • View Profile
Instead of disabling the GPS module with the A3 pin, you could try stopping its UART before WiFi transmission with `Gps_serial.end()`. This will stop some interrupts and maybe get things working. Hopefully you can start it again with `Gps_serial.begin(GPSBaud)`

You could also try testing while on USB power. Trying while plugged into your computer might be a good start but finding a 5V power supply that can provide >1A of current might be a good test too.

Let me know if any of this helps!



Ed

  • Newbie
  • *
    • Posts: 3
    • View Profile
Instead of disabling the GPS module with the A3 pin, you could try stopping its UART before WiFi transmission with `Gps_serial.end()`. This will stop some interrupts and maybe get things working. Hopefully you can start it again with `Gps_serial.begin(GPSBaud)`

I've only just had time to take another look at this. It looks like this suggestion has resolved the issue though! Looks like if I stop the Gps_Serial it works fine.

Thank you so much for your help, may have never got there on my own


 

SMF spam blocked by CleanTalk