Sending photo over HTTP

Hey guys,

So, been working on my project, which involves a JPEG image from an SD card getting sent over LoRa to a Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500 with a LoRa wing.

I have the code for the Arduino with an SD card, where the receiving feather sends a number for which packet it wants, and the arduino replies. Each packet can have a max length of 251 but I made all my packets 250 bytes long for simplicity.

My question is, On the feather side, how should I store the information, then send it over HTTP to a server? I can use the feather to make GET and POST requests, however, I have no idea how to send the image.

Note, there is more to the project by a long shot, these scripts are modified examples so I can add the code to send and receive images to the full scripts after I figure it out.

Arduino with SD card-

// rf95_reliable_datagram_server.pde
// -*- mode: C++ -*-
// Example sketch showing how to create a simple addressed, reliable messaging server
// with the RHReliableDatagram class, using the RH_RF95 driver to control a RF95 radio.
// It is designed to work with the other example rf95_reliable_datagram_client
// Tested with Anarduino MiniWirelessLoRa, Rocket Scream Mini Ultra Pro with the RFM95W

#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#include <SD.h>

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2
#define RF95_FREQ 915.0
// Singleton instance of the radio driver
RH_RF95 driver(6, 3);

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, SERVER_ADDRESS);

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

void setup()
{
  // Rocket Scream Mini Ultra Pro with the RFM95W only:
  // Ensure serial flash is not interfering with radio communication on SPI bus
  //  pinMode(4, OUTPUT);
  //  digitalWrite(4, HIGH);
  pinMode(5, OUTPUT);
  digitalWrite(5, HIGH);
  Serial.begin(9600);
  delay(100);
  SPI.begin();

  while (!Serial) ; // Wait for serial port to be available
  while (!SD.begin(8)) {
    Serial.println(F("SD Card Error!")); delay(1000);
  }
  Serial.println(F("SD Card detected."));
  digitalWrite(5, LOW);
  delay(10);
  digitalWrite(5, HIGH);
  delay(10);
  if (!manager.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  //  driver.setTxPower(23, false);
  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  // transmitter RFO pins and not the PA_BOOST pins
  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
  // Failure to do that will result in extremely low transmit powers.
  //  driver.setTxPower(14, true);
  // You can optionally require this module to wait until Channel Activity
  // Detection shows no activity on the channel before transmitting by setting
  // the CAD timeout to non-zero:
  driver.setCADTimeout(10000);
  if (!driver.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
}


// Dont put this on the stack:
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

int fileLen;

void getSDData(int packNum, uint8_t from) {
  Serial.println("Retriving SD data...");
  File file = SD.open("1.JPG", FILE_READ);
  fileLen = file.size();
  boolean kg = file.seek(packNum * 250);
  if (kg == true) {
    if (fileLen - packNum * 250 >= 250) {
      Serial.println("Sending 250 byte packet");
      Serial.println(file.position());
      uint8_t data[250];
      for (int i = 0; i <= 250; i++) {
        data[i] = file.read();
      }
      if (!manager.sendtoWait(data, sizeof(data), from))
        Serial.println("sendtoWait failed");
    }
    else {
      int left = fileLen - file.position();
      uint8_t data[left];
      for (int i = 0; i <= left; i++) {
        data[i] = file.read();
      }
      if (!manager.sendtoWait(data, sizeof(data), from))
        Serial.println("sendtoWait failed");
    }
  }
  else {
    uint8_t data[] = "NA";
    if (!manager.sendtoWait(data, sizeof(data), from))
      Serial.println("sendtoWait failed");
  }
}



void loop()
{
  if (manager.available())
  {
    // Wait for a message addressed to us from the client
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (manager.recvfromAck(buf, &len, &from))
    {
      Serial.println("\n-----");
      Serial.print("got request from : 0x");
      Serial.print(from, HEX);
      Serial.print(": ");
      Serial.println((char*)buf);
      int sec = String((char*)buf).toInt();
      getSDData(sec, from);
      // Send a reply back to the originator client

    }
  }
}

Current feather code-

#include <RHReliableDatagram.h>
#include <RH_RF95.h>
#include <SPI.h>
#define RFM95_RST     11   // "A"
#define RFM95_CS      10   // "B"
#define RFM95_INT     6
#define RF95_FREQ 915.0

#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

RH_RF95 driver(RFM95_CS, RFM95_INT);
RHReliableDatagram manager(driver, CLIENT_ADDRESS);

void setup()
{
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);
  // Rocket Scream Mini Ultra Pro with the RFM95W only:
  // Ensure serial flash is not interfering with radio communication on SPI bus
  //  pinMode(4, OUTPUT);
  //  digitalWrite(4, HIGH);

  Serial.begin(9600);
  delay(100);
  while (!Serial) ; // Wait for serial port to be available
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);
  if (!manager.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  //  driver.setTxPower(23, false);
  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  // transmitter RFO pins and not the PA_BOOST pins
  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true.
  // Failure to do that will result in extremely low transmit powers.
  //  driver.setTxPower(14, true);
  // You can optionally require this module to wait until Channel Activity
  // Detection shows no activity on the channel before transmitting by setting
  // the CAD timeout to non-zero:
  driver.setCADTimeout(10000);
  if (!driver.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);
}

uint8_t photobuf[50][251];
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];

int packNum = 0;
char pm[2];

void loop()
{
  itoa(packNum, pm, 10);
  if (packNum <= 50) {
    Serial.println("Sending to rf95_reliable_datagram_server");

    // Send a message to manager_server
    if (manager.sendtoWait((uint8_t *)pm, 2, SERVER_ADDRESS))
    {
      // Now wait for a reply from the server
      uint8_t len = sizeof(buf);
      uint8_t from;
      if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
      {
        Serial.print("got reply from : 0x");
        Serial.print(from, HEX);
        Serial.print(": ");

        Serial.println((char*)buf);
        Serial.println(sizeof((char*)buf));
        String in = (char*)buf;
        if(in=="NA"){
          printMemory();
          Serial.println("NA FOUND");
        }
        //     memcpy(buf, photobuf[packNum] [ 251]);

        for (int i = 0; i < 250; i++) {
          photobuf [packNum][i] = buf [i];
        }

        packNum++;
      }
      else
      {
        Serial.println("No reply, is rf95_reliable_datagram_server running?");
      }
    }
    else
      Serial.println("sendtoWait failed");
    delay(500);
  }
  else {
    printMemory();
  }
}
void printMemory(){
  Serial.println("-----------------------------------");
    for (int a = 0; a < 50; a++) {
      for (int i = 0; i < 251; i++) {
        Serial.write(photobuf[a][i]);

      }
      Serial.print("\n");
    }
    while (true);
}