0
       if(jsonDoc["delayOn"].as<int>() <= 255 && jsonDoc["delayOff"].as<int>() <= 255 && jsonDoc["delayUnitOn"].as<int>() <= 2 && jsonDoc["delayUnitOff"].as<int>() <= 2 && 
         jsonDoc["mode"].as<int>() <= 1 && jsonDoc["blink"].as<int>() <= 1 && 
         jsonDoc["timeOnHour"].as<int>() <= 23 && jsonDoc["timeOnMinute"].as<int>() <= 59 && 
         jsonDoc["timeOffHour"].as<int>() <= 23 && jsonDoc["timeOffMinute"].as<int>() <= 59) {

        int val;
        int addr_init = (relay*eepromSlotsPerRelayPin)*sizeof(int);
        
        val = jsonDoc["blink"].as<int>();
        EEPROM.put(addr_init,val);
        if(jsonDoc["blink"].as<int>()==1){ //0=off,1=on        

          val = jsonDoc["mode"].as<int>();
          EEPROM.put(addr_init+(5*sizeof(int)),val);
          
          
          if (jsonDoc["mode"].as<int>()==0){ //blink mode

            val = jsonDoc["delayOn"].as<int>();
            EEPROM.put(addr_init+(1*sizeof(int)),val);
            val = jsonDoc["delayOff"].as<int>();
            EEPROM.put(addr_init+(3*sizeof(int)),val);
            //1=minute,0=second,2=hour
            val = jsonDoc["delayUnitOn"].as<int>();
            EEPROM.put(addr_init+(2*sizeof(int)),val);
            val = jsonDoc["delayUnitOff"].as<int>();
            EEPROM.put(addr_init+(4*sizeof(int)),val);
            EEPROM.end();
                            
          }else if(jsonDoc["mode"].as<int>()==1){ //time switch mode

            val = jsonDoc["timeOnHour"].as<int>();
            EEPROM.put(addr_init+(6*sizeof(int)),val);
            val = jsonDoc["timeOnMinute"].as<int>();
            EEPROM.put(addr_init+(7*sizeof(int)),val);
            val = jsonDoc["timeOffHour"].as<int>();
            EEPROM.put(addr_init+(8*sizeof(int)),val);
            val = jsonDoc["timeOffMinute"].as<int>();
            EEPROM.put(addr_init+(9*sizeof(int)),val);
            EEPROM.end();
          }
          else {
            request->send(412, "text/plain", "unknown mode");
            return;
          }
        }
      }
      else {
        request->send(412, "text/plain", "a parameter is not within limits");            
        return;
      }        
      
      //initBlinkPinObjs
      int addr_init;
      int val,uom;
      for(int i = 0; i<maxRelayPins; i++) {
        bPinObjs[i].pin = relayPins[i];
        //EEPROM Slot per Relay dataStruct
        //0=>enable, 1=>durationOn, 2=>durationOnTimeMeasure,  
        //3=>durationOff, 4=>durationOffTimeMeasure
        //5=>mode, 6=>timeOnHour, 7=>timeOnMinute, 
        //8=>timeOffHour, 9=>timeOffMinute

        addr_init = (i*eepromSlotsPerRelayPin)*sizeof(int);
        
        val = 0;
        EEPROM.get(addr_init,val);
       bPinObjs[i].enable = val;

        val = 0;
        EEPROM.get(addr_init+(5*sizeof(int)),val);
        bPinObjs[i].mode = val;

        val = 0;
        EEPROM.get(addr_init+(6*sizeof(int)),val);
        bPinObjs[i].timeOnHour=val;

        val = 0;
        EEPROM.get(addr_init+(7*sizeof(int)),val);
        bPinObjs[i].timeOnMinute=val;

        val = 0;
        EEPROM.get(addr_init+(8*sizeof(int)),val);
        bPinObjs[i].timeOffHour = val;

        val = 0;
        EEPROM.get(addr_init+(9*sizeof(int)),val);
        bPinObjs[i].timeOffMinute = val;
        
        //delayOn
        //convert to millisec            
        uom = 0;
        EEPROM.get(addr_init+(2*sizeof(int)),uom);
        switch(uom){
          case 0:
            bPinObjs[i].durationOn=0;
            val = 0;
            EEPROM.get(addr_init+(1*sizeof(int)),val);
            bPinObjs[i].durationOn = val*1000;
          break;
          case 1:
            bPinObjs[i].durationOn=0;
            val = 0;
            EEPROM.get(addr_init+(1*sizeof(int)),val);
            bPinObjs[i].durationOn = val*60000;
          break;
          case 2:
            bPinObjs[i].durationOn=0;
            val = 0;
            EEPROM.get(addr_init+(1*sizeof(int)),val);
            bPinObjs[i].durationOn = val*3600000;
          break;
          default:
          break;
        }       
        //delayOff
        //convert to millisec
        uom = 0;
        EEPROM.get(addr_init+(4*sizeof(int)),uom);
        switch(uom){
          case 0:
            bPinObjs[i].durationOff = 0;
            val = 0;
            EEPROM.get(addr_init+(3*sizeof(int)),val);
            bPinObjs[i].durationOff = val*1000;
          break;
          case 1:
            bPinObjs[i].durationOff = 0;
            val = 0;
            EEPROM.get(addr_init+(3*sizeof(int)),val);
            bPinObjs[i].durationOff = val*60000;
          break;
          case 2:
            bPinObjs[i].durationOff = 0;
            val = 0;
            EEPROM.get(addr_init+(3*sizeof(int)),val);
            bPinObjs[i].durationOff = val*3600000;
          break;
          default:
          break;
        }    
      }
--JSON INPUT printed from server--

relay:0
blink:1
mode:1
delayOn:56
delayOff:2
delayUnitOn:0
delayUnitOff:0
timeOnHour:5
timeOnMinute:56
timeOffHour:7
timeOffMinute:48
OUTPUT printed from server:
--Objects content--
Size of INT:4
---------0--------- init addr: 0
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------1--------- init addr: 40
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------2--------- init addr: 80
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------3--------- init addr: 120
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------4--------- init addr: 160
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------5--------- init addr: 200
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------6--------- init addr: 240
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------7--------- init addr: 280
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0
---------8--------- init addr: 320
[0]enable: 0
[1]durationOn: 0
[2]durationOnUom: 0
[3]durationOff: 0
[4]durationOffUom: 0
[5]mode: 0
[6]onHr: 0
[7]onMin: 0
[8]offHr: 0
[9]offMin: 0

This is inside an esp8266 async webserver server.on method. My EEPROM.begin is in setup function. Initially, only the first put within a block becomes committed . Now, nothing is registering after I implemented the sizeof(int) inside addresses.

The intention is to store int data passed thru http post per relay pin [total of 9 pins]. The program then uses the data to perform on a relay:

  • blink
  • switch on/off based on time (hour,minute) ...

I've tried all sorts to fix:

  • commit,end after every put
  • EEPROM.begin(512) then commit & end on every put
  • add delays
  • use end only instead of commit
  • add address range for sizeof(int)
6
  • try the arduino example code
    – jsotola
    Mar 15 at 16:31
  • 1
    how do you know that commit applies to only the first put?
    – jsotola
    Mar 15 at 16:33
  • I print it in Serial. I did try the write & read from sample but it does not meet my requirement to store int.
    – Tinker Ben
    Mar 15 at 18:49
  • (relay*eepromSlotsPerRelayPin)+(relayDataIndex * sizeOf(int)) will try this out as the address values based on @VictorTiamson and @RollyAvecilla suggestions.
    – Tinker Ben
    Mar 16 at 13:59
  • 1
    New challenge, now nothing is registering. Edited the code displayed in post with my updates.
    – Tinker Ben
    Mar 20 at 0:40

1 Answer 1

0

Weird, i commented out the val=0; before EEPROM.gets also replaced EEPROM.end with EEPROM.commit.

This is the output now:

--Objects content--
Size of INT:4
---------0--------- init addr: 0
[0]enable: 1
[4]durationOn: 3000
[8]durationOnUom: 0
[12]durationOff: 2000
[16]durationOffUom: 0
[20]mode: 1
[24]onHr: 9
[28]onMin: 11
[32]offHr: 9
[36]offMin: 12
---------1--------- init addr: 40
[40]enable: 1
[44]durationOn: 0
[48]durationOnUom: -1
[52]durationOff: 0
[56]durationOffUom: -1
[60]mode: -1
[64]onHr: -1
[68]onMin: -1
[72]offHr: -1
[76]offMin: -1
---------2--------- init addr: 80
[80]enable: 1
[84]durationOn: 0
[88]durationOnUom: -1
[92]durationOff: 0
[96]durationOffUom: -1
[100]mode: -1
[104]onHr: -1
[108]onMin: -1
[112]offHr: -1
[116]offMin: -1
---------3--------- init addr: 120
[120]enable: 1
[124]durationOn: 0
[128]durationOnUom: -1
[132]durationOff: 0
[136]durationOffUom: -1
[140]mode: 1
[144]onHr: 5
[148]onMin: 56
[152]offHr: 7
[156]offMin: 48
---------4--------- init addr: 160
[160]enable: 1
[164]durationOn: 0
[168]durationOnUom: -1
[172]durationOff: 0
[176]durationOffUom: -1
[180]mode: -1
[184]onHr: -1
[188]onMin: -1
[192]offHr: -1
[196]offMin: -1
---------5--------- init addr: 200
[200]enable: 1
[204]durationOn: 0
[208]durationOnUom: -1
[212]durationOff: 0
[216]durationOffUom: -1
[220]mode: -1
[224]onHr: -1
[228]onMin: -1
[232]offHr: -1
[236]offMin: -1
---------6--------- init addr: 240
[240]enable: 1
[244]durationOn: 0
[248]durationOnUom: -1
[252]durationOff: 0
[256]durationOffUom: -1
[260]mode: -1
[264]onHr: -1
[268]onMin: -1
[272]offHr: -1
[276]offMin: -1
---------7--------- init addr: 280
[280]enable: 1
[284]durationOn: 0
[288]durationOnUom: -1
[292]durationOff: 0
[296]durationOffUom: -1
[300]mode: -1
[304]onHr: -1
[308]onMin: -1
[312]offHr: -1
[316]offMin: -1
---------8--------- init addr: 320
[320]enable: 1
[324]durationOn: 0
[328]durationOnUom: -1
[332]durationOff: 0
[336]durationOffUom: -1
[340]mode: -1
[344]onHr: -1
[348]onMin: -1
[352]offHr: -1
[356]offMin: -1


--JSON inputs--

relay:0
blink:1
mode:1
delayOn:3
delayOff:2
delayUnitOn:0
delayUnitOff:0
timeOnHour:9
timeOnMinute:11
timeOffHour:9
timeOffMinute:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.