0

I'm trying to make a POST http request to an elastic search server, but I am getting a 603 status and a failure. Here is the output when i am making the request. The chip itself works and the get request on the example works as well. I can send texts. the problem is with the code itself, but I don't know where.

---> AT+HTTPTERM
<--- OK
---> AT+HTTPINIT
<--- OK
---> AT+HTTPPARA="CID"
<--- OK
---> AT+HTTPPARA="UA"
<--- OK
---> AT+HTTPPARA="URL"
<--- OK
---> AT+HTTPPARA="CONTENT"
<--- OK
---> AT+HTTPDATA=150,100000
<--- DOWNLOAD
<--- OK
---> AT+HTTPACTION=1
<--- OK
Status: 603
Len: 0
    ---> AT+HTTPREAD
    <--- OK
Failed!

Here is the arduino code, mostly copied from the FONA test available from the FONA library.

#include "Adafruit_FONA.h"
#include "SoftwareSerial.h"

//FONA stuff
char replybuffer[255];
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);
SoftwareSerial *fonaSerial = &fonaSS;
Adafruit_FONA fona = Adafruit_FONA(FONA_RST);
uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0);

uint8_t type;


void setup() {
  while (!Serial);
  Serial.begin(115200);
  Serial.println(F("Initializing FONA"));
  Serial.println(F("Initializing....(May take 3 seconds)"));

  fonaSerial->begin(4800);
  if (! fona.begin(*fonaSerial)) {
    Serial.println(F("Couldn't find FONA"));
    while (1);
  }

  Serial.println(F("FONA is OK"));
  Serial.print(F("Found FONA 800H"));

  char imei[16] = {0}; // MUST use a 16 character buffer for IMEI!
  uint8_t imeiLen = fona.getIMEI(imei);
  if (imeiLen > 0) {
    Serial.print("Module IMEI: "); Serial.println(imei);
  }

  fona.setGPRSNetworkSettings(F("TM"));
  //fona.setHTTPSRedirect(true);

  fona.enableGPRS(false);
  while(!fona.enableGPRS(true));


  flushSerial();

  uint16_t vbat;  
  if (! fona.getBattPercent(&vbat)) {
    Serial.println(F("Failed to read Batt"));
  } else {
    Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%"));
  }

}

void loop() {


  uint16_t vbat;  
  if (! fona.getBattPercent(&vbat)) {
    Serial.println(F("Failed to read Batt"));
  } else {
    Serial.print(F("VPct = ")); Serial.print(vbat); Serial.println(F("%"));
  }

  float humidityInside = dhtinside.readHumidity() -10;
  float temeratureInside = dhtinside.readTemperature();
  float humidityOutside = dhtoutside.readHumidity();
  float temeratureOutside = dhtoutside.readTemperature();

  uint16_t statuscode;
  int16_t length;
  char conversion[8];
  String data = "{\"outside.temperature\":" + 
              String(temeratureOutside) +
              "," + "\"outside.humidity\":" +
              String(humidityOutside) +
              "," + "\"inside.temperature\":" + 
              String(temeratureInside) + 
              "," + "\"inside.humidity\":" +
              String(humidityInside) + 
              "," + "\"timestamp\":" + 
              String(myRTC.year) + 
              "-0" +
              String(myRTC.month) + 
              "-" +
              String(myRTC.dayofmonth) +
              "T" + 
              String(myRTC.hours) +
              ":" + 
              String(myRTC.minutes) +
              ":" +
              String(myRTC.seconds) + 
              "\"," + "\"battery\":" +
              String(vbat) +
              "}";

  Serial.println(data); 

  char dataChar[152];

  data.toCharArray(dataChar, 151);

  flushSerial();

  Serial.println(F("****"));
  flushSerial();
  if (!fona.HTTP_POST_start("https://elastic:ZZFPKxXvZX1T@9195f7cad1252e0d4.eastus2.azure.elastic-cloud.com:9243/honeycomb/_doc", F("application/json"), (uint8_t *) dataChar, strlen(dataChar), &statuscode, (uint16_t *)&length)) {
    Serial.println("Failed!");
  }else{
    while (length > 0) {
    while (fona.available()) {
      char c = fona.read();

    #if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
        loop_until_bit_is_set(UCSR0A, UDRE0); // Wait until data register empty. 
        UDR0 = c;
    #else
        Serial.write(c);
    #endif

        length--;
        if (! length) break;
      }
    }
    Serial.println(F("\n****"));
    fona.HTTP_POST_end();

  }

  delay(10000);
}

void flushSerial() {
  while (Serial.available())
    Serial.read();
}

1 Answers1

0

I dont know c++ and I dont know the "Feather FONA", but I have been facing similar problems with my "TTgo t-call sim800 v1.3" micropython board.

When I look at the output you posted I would say you forgot to enable HTTPS. Again I don't know c++, but if "https://elastic:ZZFPKxXvZX1T@9195f7cad1252e0d4.eastus2.azure.elastic-cloud.com:9243/honeycomb/_doc" is the URL you making the request to, you have to enable HTTPS first.

In your output there shoud be a line:

AT+HTTPSSL=1
OK

If you try to enable HTTPS, but you get an error like this:

AT+HTTPSSL=1
ERROR

your modem may not support HTTPS. You then have to fall back to HTTP.

user2956577
  • 91
  • 1
  • 10