メインコンテンツへスキップ

BASIC IDE Code To Send Data File To Email

コメント

6件のコメント

  • jseanor

    @mjf317

    Excellent submission!
    I have cleaned up the formatting just a bit.
    The reason you are getting a syntax error on the TSET1, 0 is because you are missing a space before the 1 :wink:


    Do you use this feature a lot? Primarily for historical data?

     

     

    0
  • mjf317

    Jordan,

    That was fast, thank you for the reply!

    Corrected my syntax and running with zero errors now.

    This is my first go at using any BASIC IDE script. You helped me out a great deal with the export block descriptor / email send via push button from the Viewon project a while back. I think that for now this will be the only thing that I'm doing in the BASIC script for but the possibilities are endless.

    If I get some more time Id like to play around with some other functions. We are very interested in logging data and pulling historical files. My goal here is to pull a 6 hour historical log file every 6 hours. We are importing that information into a database and using it to give equipment performance status reports on our remote sites. This method seems to work well because I can pull the historical log every 6 hours and not worry about the historical information in the flexy getting overwritten on a FIFO basis. This also enables me to monitor more tags so that the memory limitation isn't so much of an issue.

    I think we talked before about putting a huge memory card in the SD slot, periodically dumping the .dat file from the flexy onto the card and then retrieving that .dat file or files on an interval.

    This bring a second question to mind: can the file thats being emailed via the SENDMAIL function be customized to give a unique date and time as the file name? (IE using TIME$)

    I'm not sure of the syntax here but something like:
    SENDMAIL "toanyemail@anyemail.com", " CCanyemail@anyemail.com, secondCCanyemail@anyemail.com ", "6 Hour Auto Log File", "6 Hour Log File Auto Send from Sender: "TIME$"&[$dtHT $ftT $st_h6 $et_m0]"

    0
  • hms_support

    @mjf317

    This is possible to do in the block descriptor.

    See the example below:

    SENDMAIL "toanyemail@anyemail.com", " CCanyemail@anyemail.com, secondCCanyemail@anyemail.com ", "6 Hour Auto Log File", "6 Hour Log File Auto Send from Sender: " + "&[$dtHT $ftT $st_h6 $et_s0 $fnMyCustomFileName" +" " + time$ + "]"

    image

    "
    You can also break up the time into different variables by parsing it and then adding it to your block descriptor to create a more desirable format (Example Below)

    T$ = Time$
    year$ = T$(7 To 10)
    mon$ = T$(4 To 5)
    date$ = T$(1 To 2)
    hour$ = T$(12 To 13)
    min$ = T$(15 To 16)
    sec$ = T$(18 To 19)

    SENDMAIL "toanyemail@anyemail.com", " CCanyemail@anyemail.com, secondCCanyemail@anyemail.com ", "6 Hour Auto Log File", "6 Hour Log File Auto Send from Sender: " + "&[$dtHT $ftT $st_h6 $et_s0$fnMyCustomFileName" + " " + hour$ + "." + min$ + " " + mon$ + date$ + year$ + "]"

    image

    0
  • jseanor

    @mjf317

    Another thing that can greatly help you here is our Export Block Descriptor builder! This tool can help you create complex export block descriptors in a very easy wizard driven format.

    https://ewonsupport.biz/ebd

     

     

    0
  • mjf317

    REM PROGRAM TO EXE A 6 HOUR HISTORICAL DAT FILE SEND EVERY 2 HOURS
    Timer:
    REM DECLARE A TIMER NAME AND A WAIT TIME IN SECONDS AKA 2 HOURS IN SEC
    TSET 1, 7200
    REM WHEN TIMER STATUS IS 1 GOTO FILESEND AND SEND DATAFILE
    ONTIMER 1, "GOTO Filesend"
    END
    Filesend:
    SENDMAIL "toanyemail@anyemail.com", " CCanyemail@anyemail.com, secondCCanyemail@anyemail.com ", "6 Hour Auto Log File", "6 Hour Log File Auto Send from Sender: &[$dtHT $ftT $st_h6 $et_m0]"
    TSET 1, 0
    END


    Jordan,

    When using the above formatted code something strange is happening? It seems that the first log file gets sent and then the program ends. I don't get log files per interval defined by the timer after the first one gets sent.

    I changed the code and eliminated the second instance of TSET 1, 0 and everything seems to work fine.
    I think the issue there was that I did everything in the init section rather than creating a second section labeled "filesend". Im not sure if that is a coding "no-no" or not but im learning this as I go. For right now thats the only code that I have in there :smile:


    REM PROGRAM TO EXE A 6 HOUR HISTORICAL DAT FILE SEND EVERY 2 HOURS
    Timer:
    REM DECLARE A TIMER NAME AND A WAIT TIME IN SECONDS AKA 2 HOURS IN SEC
    TSET 1, 7200
    REM WHEN TIMER STATUS IS 1 GOTO FILESEND AND SEND DATAFILE
    ONTIMER 1, "GOTO Filesend"
    END
    Filesend:
    SENDMAIL "toanyemail@anyemail.com", " CCanyemail@anyemail.com, secondCCanyemail@anyemail.com ", "6 Hour Auto Log File", "6 Hour Log File Auto Send from Sender: &[$dtHT $ftT $st_h6 $et_m0]"
    END

    0
  • jseanor

    @mjf317

    So the problem from what I see is the TSET 1, 0 line. What that line does is it actually disables the timer. If the goal is to send it on regular intervals I'd just drop that line entirely. Additionally, leaving that code in the init section isn't a big issue because you are using a timer.

    The INIT section can essentially be pictured as the initialization section. It is where you define all of your watchdogs that will run in the background such as timers. So by calling TSET 1, 7200 you are creating a watchdog that will execute every 7200 seconds.

    0

サインインしてコメントを残してください。