So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Bonzo
#81491 I have spent three very long evenings on this and can not find the problem. I am beginning to suspect it is a conflict with SPIFFS and softwareserial.

I did not want to use softwareserial but can not get the code to run if I remove it. Currently I have RX from the GPS module ( NEO-6M on a breakout board with arial attached ) on pin D1 and TX on pin D2. As I say this works for the code mentioned below. My other problem is my PC is nowhere near a window and I do not have a USB lead long enough to reach one!

If I run the code from https://circuitdigest.com/microcontroll ... emcu-esp12 I get a webpage with the correct data. But when I add the SPIFFs code I get no data; please can somebody point out where I am going wrong.

Code: Select all#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <FS.h>   // Include the SPIFFS library

TinyGPSPlus gps;  // The TinyGPS++ object
SoftwareSerial ss(4, 5); // The serial connection to the GPS device

float latitude , longitude;
int year , month , date, hour , minute , second;
String date_str , time_str , lat_str , lng_str;
int pm, i;

void setup()
{
  Serial.begin(115200);
  ss.begin(9600);
  Serial.println();

  SPIFFS.begin();  // Start the SPI Flash Files System
  // Next lines have to be done ONLY ONCE!!!!!When SPIFFS is formatted ONCE you can comment these lines out!!
  /*Serial.println("Please wait 30 secs for SPIFFS to be formatted");
      SPIFFS.format();
      Serial.println("Spiffs formatted");*/
}

void loop()
{

  while (ss.available() > 0)
    if (gps.encode(ss.read()))
    {
      if (gps.location.isValid())
      {
        latitude = gps.location.lat();
        lat_str = String(latitude , 6);
        longitude = gps.location.lng();
        lng_str = String(longitude , 6);
      }
      if (gps.date.isValid())
      {
        date_str = "";
        date = gps.date.day();
        month = gps.date.month();
        year = gps.date.year();
        if (date < 10)
          date_str = '0';
        date_str += String(date);
        date_str += " / ";
        if (month < 10)
          date_str += '0';
        date_str += String(month);
        date_str += " / ";
        if (year < 10)
          date_str += '0';
        date_str += String(year);
      }
      if (gps.time.isValid())
      {
        time_str = "";
        hour = gps.time.hour();
        minute = gps.time.minute();
        second = gps.time.second();
        minute = (minute + 30);
        if (minute > 59)
        {
          minute = minute - 60;
          hour = hour + 1;
        }
        hour = (hour + 5) ;
        if (hour > 23)
          hour = hour - 24;
        if (hour >= 12)
          pm = 1;
        else
          pm = 0;
        hour = hour % 12;
        if (hour < 10)
          time_str = '0';
        time_str += String(hour);
        time_str += " : ";
        if (minute < 10)
          time_str += '0';
        time_str += String(minute);
        time_str += " : ";
        if (second < 10)
          time_str += '0';
        time_str += String(second);
        if (pm == 1)
          time_str += " PM ";
        else
          time_str += " AM ";
      }
    }

  String s = "";
  s += lat_str;
  s += "+";
  s += lng_str;
  s += " ";
  s += date_str;
  s += " ";
  s += time_str;

  // Save data to SPIFFS
  // open file for writing
  File f = SPIFFS.open("/GPS.txt", "a+");
  if (!f) {
    Serial.println("file open failed");
  }
  Serial.println("====== Writing to SPIFFS file =========");
  f.println(s);
  f.close();
  String contents = "";

  // open file for reading
  f = SPIFFS.open("/GPS.txt", "r");
  if (!f) {
    Serial.println("file open failed");
  }  Serial.println("====== Reading from SPIFFS file =======");
  for (i = 0; i < f.size(); i++) //Read upto complete file size
  {
    Serial.print((char)f.read());
  }
  f.close();  //Close file
  Serial.println("File Closed");

  delay(6000);
}