Esp8266 NFC multi door lock system

Neither does SPIFFS unless you ask for it to be erased.

1 Like

I changed the file output to the SPIFFS.

I made it look as close to the FRAM as I could so that I did not need to change the code to change where i store the data.


bool openspiffs(){

    datafile = SPIFFS.open(carddatafile, "r+b");        // exsisting file opened
    if (!datafile){
          datafile = SPIFFS.open(carddatafile, "w+b");  // create new file
    }
  return datafile;
}

void closespiffs(){

    if (datafile){
          datafile.close();
    }
}


void writestringdata(uint16_t whatbyte, int howlong, String databuffer){
    byte s[maxnamelength+1];
    datafile.seek(DATASTART+whatbyte, SeekSet);
    
    databuffer.getBytes(s, maxnamelength);     
    datafile.write(s, howlong);
    datafile.flush();
}

String readstringdata(uint16_t whatbyte, int howlong){
  char s[maxnamelength+1];
  byte s2[maxnamelength+1];
  
  datafile.seek(DATASTART+whatbyte, SeekSet);
  datafile.read(s2, howlong);
  for ( int i = 0; i < howlong; i++)
    s[i] = char(s2[i]);
  return String(s);
}


uint16_t read16data(uint16_t whatbyte){
  uint16_t out;
  uint8_t high;
  uint8_t low;
  
  datafile.seek(DATASTART+whatbyte, SeekSet);
  datafile.read(&high, 1);
  datafile.read(&low, 1);

  out = high << 8;
  out += low;
  return out;
 }

void write16data(uint16_t whatbyte, uint16_t databuffer){
  uint8_t high;
  uint8_t low;
  high = highByte(databuffer);
  low = lowByte(databuffer);
  datafile.seek(DATASTART+whatbyte, SeekSet);
  datafile.write(&high, 1);
  datafile.write(&low, 1);  
  datafile.flush();

 }
 
void getdatafromfile(){
  if (openspiffs()){
  rowIndex = read16data(0);                                                   //read the card count from fram 
  uint16_t buffer_offset = recordlength;                                    //start at record 1
    Blynk.virtualWrite(vcount, rowIndex);       // write the rowIndex to the server
    
  for (int i = 1; i <= rowIndex; i++){                                             // read all the card data
//  read16data(buffer_offset, tempindex);                                       // skip the index
    buffer_offset += 2;
    cardHolder[i] = readstringdata(buffer_offset, maxnamelength);
    buffer_offset += maxnamelength;
    cardId[i] = readstringdata(buffer_offset, maxuidlength);
    buffer_offset += maxuidlength;
    accessFlags[i] = read16data(buffer_offset);
    buffer_offset += 2;
    yield();
  }
  closespiffs();
  }
}

void dumpdatafromfile(){
  String ch;
  String cId;
  int af;
  int ri;
  int tempIndex;
  uint16_t buffer_offset = recordlength;                                    //start at record 1

    if ( openspiffs()){
    tempIndex = read16data(0);                                                   //read the card count from fram address 0
    terminal.println("index "+String(tempIndex));
//  for (int i = 1; i <= tempIndex; i++){                                             // read all the card data
    ri = read16data(buffer_offset);
    buffer_offset += 2;
    ch = readstringdata(buffer_offset, maxnamelength);
    buffer_offset += maxnamelength;
    cId = readstringdata(buffer_offset, maxuidlength);
    buffer_offset += maxuidlength;
    af = read16data(buffer_offset);
    buffer_offset += 2;
    terminal.println("index: " + String(ri) + " holder:  " + ch + " ID:  " + cId + " flags: " + String(af));
    yield();
//  }
  terminal.flush();
  closespiffs();
    }
}

3 Likes

I posted the project on github

2 Likes

Added OTA for updates and fixed a few bugs. Updated all the hardware to use the SPIFFS memory. I am now working on the hardware getting it ready for permanent installation. I will post new code on github tonight,

ESP8266, power supply and relay installed in electrical box. The NFC module will be installed in a second box outside the door.

elbox

Updating the code to make the number of locks unlimited. I should have it up in a day or two.

1 Like

Project now supports unlimited locks. Copy all is now working. Locks use wifi manager to set the BLYNK tokens for the master and current lock as well as connect to the wifi.

It does have a problem if the device does not connect to the wifi. I think I will work on making the wifi connection non blocking and use provision on demand.

2 Likes

Initial alpha release created on github

2 Likes

Version A.0.2

Alpha 2 release
Added time restrictions to the locks.
Added admin to flags

Minor bug fixes.

New prototype boards
https://drive.google.com/file/d/1U14EYc_4Kqo7vlegBX2X0XYQStzabn8C/view?usp=sharing

3 Likes

Doing 4 more doors at my hangar in California. I will test it and I hope upgrade it when the new platform is available.

:rofl::rofl::rofl:

3 Likes

qrc for project

1 Like

Finally getting around to using my own server. I had some problems getting the hardware to connect. In the end I found that the OTA update did not replace the wifi information so I had to use a cable. Too bad for the hardware that was covered in resin I guess it will never be able to connect to the private server.

After I discovered this problem I added a way to update the server name/ip from the configuration portal. I should also make it go to the portal if the hardware does not connect to the blynk server but I am still thinking about how to do that and keep the reader active so that the door can be opened.

I have not pushed the code up to github yet. I will test it for a bit first and see if there are other updates I want to make.

Updating the code and hardware for 2.0 I have it compiling but have not created the new hardware.
Created the templates for WEB and Mobile.
Removed code that did the provisioning. I expect to use Edgent.

I still have a few problems that I need to resolve but it should work.

The biggest changes are in the provisioning and communication between the locks and the programmer/master lock I may remove the need for the master lock and try to do a master data store only.

2 Likes

It is taking a bit more time than I expected. I need to learn more about 2.0

Now that PeterKnight has got me through the http api I am beginning to try to convert from bridge data to API data in this project. I am going to make some nice upgrades as I do it so that it will feel worth the time.