Ewon Technical Forum

Full Version: Store data to SD card, POST data from SD card
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
We have created a script that posts data from the eWON tags to a cloud database. This is sufficient so long as the eWON maintains its internet connection. Data is lost if the connection is lost for a period of time.

I seen some posts that indicate a script may be used to store data to the SD card on the eWON. Can a script be used to push the data from the SD card to the cloud database?

Alternatively, can data be stored to an external hard drive via a script on the eWON?
Hi,

I don't know the details of your script but yes it should be possible to store and read the data to/from a file.
You can check this thread: https://techforum.ewon.biz/thread-1048.html
It shows how to do that with a MQTT connection

Simon
Thank you. We are using REQUESTHTTPX with the POST method so I suppose your script with the MQTT connection could be modified to use the method we are using.

A snippet of our script:

Code:
PublishAllTags:
counter%=0
FOR i% = 0 TO NB% -1
      SETSYS Tag, "load",-i%
      i$= GETSYS TAG,"Name"
     
      GroupA$= GETSYS TAG,"IVGROUPA"
      GroupB$= GETSYS TAG,"IVGROUPB"
      GroupC$= GETSYS TAG,"IVGROUPC"
      GroupD$= GETSYS TAG,"IVGROUPD"
     
      IF GroupA$ = "1" And GROUPA%= 1 THEN dataToSend$ = i$ + ',unit=' + unitID$ + ' value=' + STR$ GETIO i$ : counter% = counter% +1
      @PostData(dataToSend$)
     
  NEXT i%   
END

Function PostData($dataToSend$)
  PRINT $dataToSend$
  url$ = << URL of our AWS EC2 instance >>
  method$ = "POST"
  header$ = "Content-Type=text/plain"
  REQUESTHTTPX url$, method$, header$, dataToSend$
  actionID% = GETSYS PRG,"ACTIONID"
  PRINT "request actionid is "; actionID%
  ONSTATUS "GOTO Response"
EndFn
Response: 
  eventID% = GETSYS PRG,"EVTINFO"
  IF eventID% = actionID% THEN
    SETSYS PRG,"ACTIONID",eventId%
    stat% = GETSYS PRG,"ACTIONSTAT"
    a$ = RESPONSEHTTPX "HEADER"
    PRINT "***all headers: "; a$
    a$ = RESPONSEHTTPX "STATUSCODE"
    PRINT "***status: "; a$
  ELSE
    PRINT "actionID = "; actionID%
    PRINT "eventID = "; eventID%
  ENDIF
END
(22-10-2019, 10:10 PM)simon Wrote: [ -> ]Hi,

I don't know the details of your script but yes it should be possible to store and read the data to/from a file.
You can check this thread: https://techforum.ewon.biz/thread-1048.html
It shows how to do that with a MQTT connection

Simon

I have successfully setup a SD card and can write strings of my data packages to it. Thank you.

I am now trying to send that file to my time series database which can read the entire contents of a text file into the database. I proved I could do that using the app Postman and a test text file. In Postman I had to select the Content-Type 'binary' to get the POST command to work.

This is part of the script in the eWON I am using to POST the text file to my database:

Code:
FUNCTION SendSavedData()
  $FileExist% = FS "isFile", DataPostPath$
  IF $FileExist% = -1 THEN
    RETURN
  ENDIF
  url$ = "http://<<IP ADDRESS>>/write?db=<<DATABASE>>"
  method$ = "POST"
  [b][color=#c10300]header$ = "Content-Type=text/plain"[/color][/b]
  REQUESTHTTPX url$, method$, header$, DataPostPath$
  actionID% = GETSYS PRG,"ACTIONID"
  //PRINT "request actionid is "; actionID%
  ONSTATUS "GOTO Response"

  ERASE DataPostPath$
ENDFN

I believe the issue is with the header, highlighted above. I am not certain the Content-Type to use. The database documentation has a curl example:

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt`

The highlighted text above '--data-binary' I think refers to the Content-Type but I do not know how to correlate this to the REQUESTHTTPX command.

Thoughts?
<>

At least one of the issues is I wasn't using the Export Block Descriptor configuration format to export my file. My command now looks like this:

REQUESTHTTPX url$, method$, header$, "", "[$dtUF$uf" + CurrFile$ + "]"

I receive a status code of '204' from my database, which is the expected code, but the file contents do not seem to be writing to the database.
Hi Dean,

You may need to use the Content-Type: application/x-www-form-urlencoded

Also another idea I have is to parse the file and send the content as plain data :

Code:
OPEN "file:/usr/" + CurrFile$ FOR BINARY INPUT AS 1
FileContent$ = ""
ReadNext:
IF EOF 1 THEN GOTO ReadDone
CHAR$ = GET 1,1
FileContent$ = FileContent$ + CHAR$
GOTO ReadNext
ReadDone:
PRINT "close file"
CLOSE 1

REQUESTHTTPX url$, method$, header$, FileContent$, ""


Simon
For anyone interested, I had started this thread and another on forum.hms-networks.com to determine how to accomplish this task. Most of the discussion, and the final solution is on the other thread, located here: forum.hms-networks.com/t/influx-with-requesthttpx/37585.
Thanks :-)
Do I need to know some nuances when saving data to RAID disks? Will the eWON scenario when using RAID be the same as when saving data to a regular hard drive or SD card? To be honest, I'm not the strongest specialist in computers, and I can still misunderstand something or make stupid mistakes. But I don't want to ruin everything with the wrong move. I just did an HDD RECOVERY with my drives, I need to keep them functional. Giving the disk for re-recovery is definitely not my option.