Switch to desktop version  
Export Historical CSV Report on your Extended User Memory card - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: BASIC Script (https://techforum.ewon.biz/forum-52.html)
+--- Thread: Export Historical CSV Report on your Extended User Memory card (/thread-216.html)

Pages: 1 2


Export Historical CSV Report on your Extended User Memory card - simon - 27-01-2017

Hi guys,

As of the firmware 12.1s2, you can extend the Usr memory of your eWON by using a SD card (aka EUM card).

One of the use case is to store historical data reports on this memory extension.  You'll then be able to retrieve them by using your FTP client.

Here is an example of how to generate these historical data reports on an incremental way (to paste in the init section) :

Code:
CLS
REM GENERATE REPORT EVERY HOUR
ONDATE 1,"0 * * * *","GOTO GENERATE_REPORT"
ONSTATUS "GOTO SCHEDULEDACTION_END"
GOTO GENERATE_REPORT
END


GENERATE_REPORT:
//Check if SD card is inserted or if there is enough space
SETSYS INF,"LOAD"
SDCardSize$ = GETSYS INF, "SDExtFree"
SDCardSize_Int% = Val  SDCardSize$
IF SDCardSize_Int% > 5000 THEN   // 5 MB remains
   GOSUB READ_LASTTMS
   LAST_TIME$ = @GetCurrentTimeStamp$()
   EBD_STRING$ = "$dtHL$ftT$et" + LAST_TIME$ + "$st" + LASTTMS$
   FILENAME$ = "/usr/sdext/DataReport" + LAST_TIME$ + ".txt"
   WRITEEBD  EBD_STRING$, FILENAME$
   ActionID% = GETSYS Prg, "ACTIONID"
ELSE
  LOGEVENT "EUM Card full or not present", -1
ENDIF
END

SCHEDULEDACTION_END:
  CurID% = GETSYS Prg,"EVTINFO" : REM Get ActionID
   REM : Check if it is the right schedule action to save last timestamp otherwize do nothing
   If ActionID% = CurID% THEN
     SETSYS Prg, "ACTIONID", CurID%
     CurID_Status% = GETSYS Prg,"ACTIONSTAT"
     REM Action successfully done --> Write last timestamp in file
     IF CurID_Status% = 0 THEN
       LOGEVENT "FILE " + FILENAME$ + " SUCCESSFULLY EXPORTED", 100
       @WRITETMS(LAST_TIME$)
      ELSE
        LOGEVENT "FILE " + FILENAME$ + " NOT SUCCESSFULLY EXPORTED", 0
     ENDIF
   ENDIF
END

READ_LASTTMS:
SETSYS PRG,"RESUMENEXT",1
 REM GET LAST TIMESTAMP
OPEN "file:/usr/tms.dat" FOR BINARY INPUT AS 1
  LASTTMS$ = GET 1,15
CLOSE 1

Cur_Err% = GETSYS PRG,"LSTERR"
 
IF Cur_Err% = 33 THEN //REM File does not exist
  LASTTMS$= "01011970_000000"
  SETSYS PRG,"LSTERR",0
ENDIF

SETSYS PRG,"RESUMENEXT",0
CLS

RETURN

FUNCTION WriteTMS($LastTimeStamp$):
OPEN "file:/usr/tms.dat" FOR BINARY OUTPUT AS 1
  PUT 1,$LastTimeStamp$
CLOSE 1
ENDFN

FUNCTION GetCurrentTimeStamp$()
REM TIME$ = 19/12/2014 10:03:01
$EWON_TIME$ = TIME$
$GetCurrentTimeStamp$ = $EWON_TIME$(1 To 2) + $EWON_TIME$(4 To 5) + $EWON_TIME$(7 To 10) + "_" + $EWON_TIME$(12 To 13) + $EWON_TIME$(15 To 16)+ $EWON_TIME$(18 To 19)
ENDFN



RE: Export Historical CSV Report on your Extended User Memory card - iOne - 04-02-2017

Hi!

I tested it and it works fine. O.K. I have to tried two different SD cards. The first one (SanDisk) was not working, the second one (maxflash) worked.
Then I pulled the SD during running and I got an error message "EBD fail". But even after inserting the SD again, the sdext directory came not back and also no more EBD was written.
So I think it is not allowed to pull the SD. Right? And how can I restart my system?

Thanks
iOne


RE: Export Historical CSV Report on your Extended User Memory card - Ludo - 07-02-2017

Hi Matthias,

You are right, the EUM Card shouldn't be taken off when the eWON is still running.
To get you system back up, simply perform a reset level 1 (with your EUM Card out if you want to save the data currently on it). It should put everything back to normal.

We also change the code here above.
We added a condition that checks if an EUM Card is inserted and if space is available (5Mb at least).


RE: Export Historical CSV Report on your Extended User Memory card - insyncs - 12-04-2017

Hi, 

Trying this code. I haven't put an sd card in yet, so wanted to see if there were any errors.  is all the code supposed to be in the init section? do i need to add the tags?

see attached picture.

I inserted a card and got similar errors, see second pic.

Cheers M


RE: Export Historical CSV Report on your Extended User Memory card - Ludo - 13-04-2017

(12-04-2017, 10:02 PM)insyncs Wrote: Hi, 

Trying this code. I haven't put an sd card in yet, so wanted to see if there were any errors.  is all the code supposed to be in the init section? do i need to add the tags?

see attached picture.

I inserted a card and got similar errors, see second pic.

Cheers M

Hey Marcus,

Could you let us know what is the firmware version of your eWON?

For testing purpose, you don't have to necessarily create tags (the generated file will simply be void of any tag values).
And yes, the code should go inside the Init section.


RE: Export Historical CSV Report on your Extended User Memory card - insyncs - 13-04-2017

Hi Ludo,

Using the latest version V12.0s1

Cheers M


RE: Export Historical CSV Report on your Extended User Memory card - Ludo - 14-04-2017

(13-04-2017, 05:52 PM)insyncs Wrote: Hi Ludo,

Using the latest version V12.0s1

Cheers M

Marcus,

On line 98, there seems to be an "S" character at the beginning of the line.
It shoud be (and only be)


Quote:  CurID% = GETSYS Prg,"EVTINFO" : REM Get ActionID

On line 84, the second variable is wrongly written. You need to add a space between "Val" and "SDCardSize$". It should be:

Quote:SDCardSize_Int% = Val  SDCardSize$


Hope this helps to get your code working


RE: Export Historical CSV Report on your Extended User Memory card - Controls2347 - 04-07-2017

Hi,

I have copied the above code and it appears to be creating a data report on the SD card however the reports do not contain any of the tags that we have set up to log.

If I go into the historical logging table then I can see all my tags but they are not in the data reports on the card.

How do I get the tags to record onto the card?

Regards

Chris


RE: Export Historical CSV Report on your Extended User Memory card - simon - 04-07-2017

It is maybe à time issue... Try to delete thé file tms.dat and restart the script


RE: Export Historical CSV Report on your Extended User Memory card - Controls2347 - 05-07-2017

Hi Simon,

I tried that but it doesn't seem to have made a difference.

Attached is the tag list we have setup and the report it generated on the SD card.

Am I missing something really simple here?


RE: Export Historical CSV Report on your Extended User Memory card - simon - 05-07-2017

The data are well there.
I think you were expecting to get tagnames inside while the tag Id is used because we export historical logging and not historical table.
Replace $dtHL by $dtHT in the export block descriptor used in the script.


RE: Export Historical CSV Report on your Extended User Memory card - Josh - 06-11-2017

Hi Simon,

I like this idea of using the SD card to store reports of data but it would be much more useful in our application if we could simply expand the "1,000,00 data points of storage" with the SD card. Is there a reason we wouldn't be able to tell the eWON to use the SD card as the place to store data in real time?

Thanks!
Josh


RE: Export Historical CSV Report on your Extended User Memory card - simon - 06-11-2017

Josh,

This is indeed not available for the moment. We have developed the EUM feature because we saw it as a good value for the Flexy.
Could you tell me why you need more than 1.000.000 records ? Why keeping so much data in the Flexy ? Don't you push these data to a server ?


RE: Export Historical CSV Report on your Extended User Memory card - rmac - 01-02-2019

(27-01-2017, 04:39 PM)simon Wrote: Hi guys,

As of the firmware 12.1s2, you can extend the Usr memory of your eWON by using a SD card (aka EUM card).

One of the use case is to store historical data reports on this memory extension.  You'll then be able to retrieve them by using your FTP client.

Here is an example of how to generate these historical data reports on an incremental way (to paste in the init section) :

Code:
CLS
REM GENERATE REPORT EVERY HOUR
ONDATE 1,"0 * * * *","GOTO GENERATE_REPORT"
ONSTATUS "GOTO SCHEDULEDACTION_END"
GOTO GENERATE_REPORT
END


GENERATE_REPORT:
//Check if SD card is inserted or if there is enough space
SETSYS INF,"LOAD"
SDCardSize$ = GETSYS INF, "SDExtFree"
SDCardSize_Int% = Val  SDCardSize$
IF SDCardSize_Int% > 5000 THEN   // 5 MB remains
  GOSUB READ_LASTTMS
  LAST_TIME$ = @GetCurrentTimeStamp$()
  EBD_STRING$ = "$dtHL$ftT$et" + LAST_TIME$ + "$st" + LASTTMS$
  FILENAME$ = "/usr/sdext/DataReport" + LAST_TIME$ + ".txt"
  WRITEEBD  EBD_STRING$, FILENAME$
  ActionID% = GETSYS Prg, "ACTIONID"
ELSE
 LOGEVENT "EUM Card full or not present", -1
ENDIF
END

SCHEDULEDACTION_END:
  CurID% = GETSYS Prg,"EVTINFO" : REM Get ActionID
   REM : Check if it is the right schedule action to save last timestamp otherwize do nothing
   If ActionID% = CurID% THEN
     SETSYS Prg, "ACTIONID", CurID%
     CurID_Status% = GETSYS Prg,"ACTIONSTAT"
     REM Action successfully done --> Write last timestamp in file
     IF CurID_Status% = 0 THEN
       LOGEVENT "FILE " + FILENAME$ + " SUCCESSFULLY EXPORTED", 100
       @WRITETMS(LAST_TIME$)
     ELSE
       LOGEVENT "FILE " + FILENAME$ + " NOT SUCCESSFULLY EXPORTED", 0
     ENDIF
   ENDIF
END

READ_LASTTMS:
SETSYS PRG,"RESUMENEXT",1
 REM GET LAST TIMESTAMP
OPEN "file:/usr/tms.dat" FOR BINARY INPUT AS 1
  LASTTMS$ = GET 1,15
CLOSE 1

Cur_Err% = GETSYS PRG,"LSTERR"
 
IF Cur_Err% = 33 THEN //REM File does not exist
  LASTTMS$= "01011970_000000"
  SETSYS PRG,"LSTERR",0
ENDIF

SETSYS PRG,"RESUMENEXT",0
CLS

RETURN

FUNCTION WriteTMS($LastTimeStamp$):
OPEN "file:/usr/tms.dat" FOR BINARY OUTPUT AS 1
  PUT 1,$LastTimeStamp$
CLOSE 1
ENDFN

FUNCTION GetCurrentTimeStamp$()
REM TIME$ = 19/12/2014 10:03:01
$EWON_TIME$ = TIME$
$GetCurrentTimeStamp$ = $EWON_TIME$(1 To 2) + $EWON_TIME$(4 To 5) + $EWON_TIME$(7 To 10) + "_" + $EWON_TIME$(12 To 13) + $EWON_TIME$(15 To 16)+ $EWON_TIME$(18 To 19)
ENDFN


Simon, 
This is an old thread, but Im curious about the first part of the script.

CLS
REM GENERATE REPORT EVERY HOUR
ONDATE 1,"0 * * * *","GOTO GENERATE_REPORT"
ONSTATUS "GOTO SCHEDULEDACTION_END"
GOTO GENERATE_REPORT
END


GENERATE_REPORT:
//Check if SD card is inserted or if there is enough space
SETSYS INF,"LOAD"

What is the purpose of having these two lines: 

GOTO GENERATE_REPORT
END

... right after ONSTATUS "" and before the beginning of the GENERATE_REPORT procedure description?


RE: Export Historical CSV Report on your Extended User Memory card - simon - 02-02-2019

Hi,

Indeed you are right. These two lines are useless :-)
Good point !

Simon