Shop OBEX P1 Docs P2 Docs Learn Events
embed txt file in index.htm ? — Parallax Forums

embed txt file in index.htm ?

lfreezelfreeze Posts: 174
edited 2013-03-22 16:10 in Accessories
Thanks Mike G for some really brilliant work.

I am new to the Spinneret forum. I have had success implementing the tutorial, and can access my
Spinneret. I did stumble with the setup of my Belkin router but was able to overcome those issues.

I want to attempt the following project:

1. Write variables of sensor values once each minute to the SD card on the Spinneret board,
As a txt file.

2. Embed the txt file in Index.htm.

3. Every 24 hours erase the txt file and start a new one.

This will allow a view of a log “the txt file” over a 24 hour period each time the spinneret is
Accessed.

.I believe I have the skills to accomplish items one and three. I need help/direction with item two.
Is it possible to embed at txt file in Index.htm or is there an easier way to accomplish this.

Thank you!

Larry

Comments

  • Mike GMike G Posts: 2,702
    edited 2013-03-19 15:01
    Larry, the easiest thing to do is request the text file directly. For example,
    http://123.123.123.123:5000/"the txt file"
    

    If you want to do something fancy then you'll need to HTMLize the txt file on the fly.
  • lfreezelfreeze Posts: 174
    edited 2013-03-19 16:41
    Thank you for the quick response. Your solution worked perfectly. Made me laugh as
    I spent about two days trying all kinds of exotic solutions before posting.

    Larry
  • RforbesRforbes Posts: 281
    edited 2013-03-21 15:57
    Larry,

    In regards to your message:

    For a simple SD card file creation, you might try something like the following:
    (Note: the FileExists method is a method down towards the end of the HTTPServ spin file.)
    pub Create_log
    
        SDCard.closeFile                                         'This'll close the file if it's open and does nothing if it's already closed... either way, it's closed after this.
    
        If not (FileExists(@logfile))                          'If the filename in logfile doesn't exist on the sd card, let's create it and write something to it.             
          SDcard.newfile(@logfile)                          'Create the new file   
          SDCard.openFile(@logfile, "W")              'Open in it WWWWWWWrite mode.
          SDCard.writeString(@test1)                    'Write the stuff in test1 to the file.
          SDCard.writeString(String(13))               'Stick a carriage return after it.
          SDCard.writeString(@test2)                   'Write another chunk o' stuff.
          SDCard.writeString(String(13))              'What? another carriage return???  no way!!
          SDCard.closeFile                                  'Good enough for now... close 'er up!
    
    DAT
    
    logfile  byte "Mylog.txt",0
    test1    byte "This is the first test!",0
    test2    byte "This is the second test!",0
    
    

    Now, this same concept can be used with variables:
    VAR
    long MyArray[3]
    
    pub Create_log
    
      MyArray[0]:=123
      MyArray[1]:=456
      MyArray[2]:=789
    
    
        SDCard.closeFile                                         'This'll  close the file if it's open and does nothing if it's already closed...  either way, it's closed after this.
    
        If not (FileExists(@logfile))                          'If the  filename in logfile doesn't exist on the sd card, let's create it and  write something to it.             
          SDcard.newfile(@logfile)                          'Create the new file   
          SDCard.openFile(@logfile, "W")              'Open in it WWWWWWWrite mode.
          SDCard.writeString(@test1)                    'Write the stuff in test1 to the file.
          SDCard.writeString(String(13))               'Stick a carriage return after it.
          SDCard.writeString(@test2)                   'Write another chunk o' stuff.
          SDCard.writeString(String(13))              'What? another carriage return???  no way!!
    
          SDCard.writeString(String("First long= "))
          SDCard.writeDec(MyArray[0])
          SDCard.writeString(String(13))               'Stick a carriage return after it.... hate those carriage returns!
          SDCard.writeString(String("Second long= "))
          SDCard.writeDec(MyArray[1])
          SDCard.writeString(String(13))               'Stick a carriage return after it.
          SDCard.writeString(String("Third long= "))
          SDCard.writeDec(MyArray[2])
          SDCard.writeString(String(13))               'Stick a carriage return after it.
    
          SDCard.closeFile                                  'Good enough for now... close 'er up!
    
    DAT
    
    logfile  byte "Mylog.txt",0
    test1    byte "This is the first test!",0
    test2    byte "This is the second test!",0
    
    

    Now you've got the concept for storing sensor data to an sd card... put the data into a variable, write it to the file and voila! Better than sliced bread on a stick.

    You can certainly get much more fancy than this, but it's a good foundation to start with. If you have lots of sensors, and they are all giving some kind of decimal value, you can reduce your coding by using a repeat loop:
    VAR
    long MyArray[583]
    
    pub Create_log| iter      'iter means iteration! 
    
      MyArray[0]:=123
      MyArray[1]:=456
      MyArray[2]:=789
      'on and on until we have a value in all 583 longs...
    
        SDCard.closeFile                                         'This'll   close the file if it's open and does nothing if it's already closed...   either way, it's closed after this.
    
        If not (FileExists(@logfile))                          'If the   filename in logfile doesn't exist on the sd card, let's create it and   write something to it.             
          SDcard.newfile(@logfile)                          'Create the new file   
          SDCard.openFile(@logfile, "W")              'Open in it WWWWWWWrite mode.
          SDCard.writeString(@test1)                    'Write the stuff in test1 to the file.
          SDCard.writeString(String(13))               'Stick a carriage return after it.
          SDCard.writeString(@test2)                   'Write another chunk o' stuff.
          SDCard.writeString(String(13))              'What? another carriage return???  no way!!
    
      repeat iter from 0 to 582
          SDCard.writeString(String("Long "))
          SDCard.writeDec(iter)
          SDCard.writeString(String(":"))              
          SDCard.writeDec(MyArray[iter])
          SDCard.writeString(String(13))             'Stick a carriage return after it.... STILL hate those carriage returns!
         
          SDCard.closeFile                                  'Good enough for now... close 'er up!
    
    DAT
    
    logfile  byte "Mylog.txt",0
    test1    byte "This is the first test!",0
    test2    byte "This is the second test!",0
    
    
  • lfreezelfreeze Posts: 174
    edited 2013-03-22 05:16
    Thanks for the response. The examples you provided will certainly be a big help. The Spinneret is an
    Amazing device. I constantly find myself jumping three steps ahead with coding, only to crash and burn
    Due to my lack of knowledge. I will modify my code with your examples and see where it leads me,
    Thanks again.

    Larry
  • RforbesRforbes Posts: 281
    edited 2013-03-22 16:10
    No problem at all! :)

    Also- one thing to note in the examples above.... if the file already exists, it does nothing. It's sort of a one-shot as it's written. To RE-write the file, simply add the line "SDCard.deleteEntry(@logfile)" as follows:
    SDCard.closeFile                                         'This'll   close the file if it's open and does nothing if it's already closed...   either way, it's closed after this. 
    
    SDCard.deleteEntry(@logfile)                             'This'll get rid of the file so you can re-write to it.     
    
    If not (FileExists(@logfile))                          'If the   filename in logfile doesn't exist on the sd card, let's create it and   write something to it.
         SDcard.newfile(@logfile)                          'Create the new file
    
    Again, this is very crude... but good to tinker with until you get the hang of it.
Sign In or Register to comment.