File System

See File System for a general discussion of the WiConnect file system.

The commands for creating files are file_create and http_download.

Below are provided examples of various uses of the commands for manipulating files.

Prerequisites

These examples assume you have python installed on your test platform (available for Windows, Linux or Mac).

It is also assumed you have a WiConnect module with a WiConnect terminal running.

Both your test platform and the WiConnect module should be connected to the same network. See Configuring the Module for a Wi-Fi Network.

In the examples below, "on your test platform" means at a command prompt in a terminal on your test platform, and "in the WiConnect terminal" means at the prompt of the WiConnect terminal connected to your module.

File Types

File types are used internally by the WiConnect file system. A range of file types is set aside for custom user types. Unless you have a custom use for the file type, create files with the default type of 0xFE.

The 0xFE type is used by default if you don't provide the <type> parameter to the file_create command or the http_download command. For example:

> file_create my_file.txt 39

If you wish to supply a <crc> parameter for the file_create command, you must supply a <type> argument as a placeholder. See the example below in Using file_create with a CRC.

Verifying File Integrity with a Checksum

A file checksum can be supplied when creating a file, to ensure that only a valid file is stored in the WiConnect file system.

The algorithm for generating the CRC (Cyclic Redundancy Check) is described in File System, File Checksum.

Using file_create with a CRC

To generate the CRC, download the crc_wiconnect.py python script. This demonstrates the parameters for the CRC algorithm.

Run the demonstration on your test platform, giving the file crc_wiconnect.py as the filename parameter:

python crc_wiconnect.py crc_wiconnect.py

Assuming the file has CR-LF line endings, the length and CRC are calculated as follows in the output:

filepath: crc_wiconnect.py
length:   3409
CRC:      0x3ed6

file_create command:
> fcr <filename> <length> <version> <type> <crc>
Example:
> fcr crc_wiconnect.py 3409 1.0.0 0xFE 0x3ed6

The crc_wiconnect.py output example file_create command shows how to provide the parameters. Note that the file type must be supplied as a placeholder. The default file type of 0xFE is used here.

In the WiConnect Terminal, issue the command as supplied to create the file crc_wiconnect.py on the module file system:

> fcr crc_wiconnect.py 3409 1.0.0 0xFE 0x3ed6

Immediately after issuing the command, send the contents of the file crc_wiconnect.py to the terminal.

If after the file is created, the calculated CRC doesn't match the CRC specified, the following error is displayed:

Failed to verify checksum

and WiConnect sets the file type to 0xFF invalid, effectively cancelling file creation.

If the CRC matches, the file is successfully created:

File created

To verify that the file has been created, in the WiConnect terminal issue the ls -l command.

File created
> ls -l
!  # Type  Flags  Hnd    Size       Version  Filename
...
#  6 e-FE   0021   39    3409       1.0.0.0  crc_wiconnect.py
...

To verify the file contents visually, open the file and read its contents:

> fop crc_wiconnect.py
[2015-03-09 | 05:58:10: Opened: 0]
0
> read 0 3409
#!/usr/bin/env python
# -*- coding: utf8 -*-

# CRC CCITT
...
if __name__ == '__main__':
    main()

[2015-03-09 | 05:58:15: Closed: 0]

You can also supply a CRC with the http_download command.

Downloading Files from an HTTP Server

The http_download command allows you to download one or many files from an HTTP server.

You can run a local HTTP server on your test platform using python with the command line:

> python -m SimpleHTTPServer
Serving HTTP on 0.0.0.0 port 8000 ..

The python HTTP server root directory is the directory from which the python command was issued.

The Web App development system runs a local HTTP server on your system. The file examples shown below refer to the files generated in Web App development. Running the Web App development system is explained in Web App Customization.

Assuming your test platform HTTP server is at the address 10.5.6.60:5002, the following http_download commands, issued in the WiConnect terminal, download the files from the server to your module file system:

hdo http://10.5.6.60:5002/index.html webapp/index.html 
hdo http://10.5.6.60:5002/webapp/unauthorized.html webapp/unauthorized.html
hdo http://10.5.6.60:5002/webapp/wiconnect.css.gz webapp/wiconnect.css.gz
hdo http://10.5.6.60:5002/webapp/wiconnect.js.gz webapp/wiconnect.js.gz

Note that there's no need to specify the length of the files, as this is supplied by the HTTP server.

The response is similar to the following:

> hdo http://10.5.6.60:5002/index.html webapp/index.html
Downloading: webapp/index.html to flash file system
Request GET /webapp/index.html
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Success
> hdo http://10.5.6.60:5002/index.html webapp/index.html
Downloading: webapp/index.html to flash file system
Request GET /index.html
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Success
> hdo http://10.5.6.60:5002/webapp/wiconnect.css.gz webapp/wiconnect.css.gz
Downloading: webapp/wiconnect.css.gz to flash file system
Request GET /webapp/wiconnect.css.gz
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Success
> hdo http://10.5.6.60:5002/webapp/wiconnect.js.gz webapp/wiconnect.js.gz
Downloading: webapp/wiconnect.js.gz to flash file system
Request GET /webapp/wiconnect.js.gz
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Success

Downloading Multiple Files with a File Manifest

The http_download command can download multiple files using a json manifest.

The example below demonstrates downloading the files for a modified Web App from a server at http://10.5.6.60:5002.

Issue the http_download command with the -m option. Note that you must supply the length of the manifest file.

> hdo -m 814

Then immediately send the manifest file. The file length supplied assumes CR-LF line endings.

{
   "path"  : "http://10.5.6.60:5002",
   "files" : [
        {
            "remote"  : "index.html",
            "local"   : "webapp/index.html",
            "version" : "1.0.1",
            "flags"   : "eu",
        },
        {
            "remote"  : "webapp/unauthorized.html",
            "local"   : "webapp/unauthorized.html",
            "version" : "1.0.1",
            "flags"   : "eu",
        },
        {
            "remote"  : "webapp/wiconnect.css.gz",
            "local"   : "webapp/wiconnect.css.gz",
            "version" : "1.0.1",
            "flags"   : "eu",
        },
        {
            "remote"  : "webapp/wiconnect.js.gz",
            "local"   : "webapp/wiconnect.js.gz",
            "version" : "1.0.1",
            "flags"   : "eu",
        }
    ]
}

The response is similar to the following:

Downloading: webapp/index.html to flash file system
Request GET /index.html
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Downloading: webapp/unauthorized.html to flash file system
Request GET /webapp/unauthorized.html
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Downloading: webapp/wiconnect.css.gz to flash file system
Request GET /webapp/wiconnect.css.gz
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Downloading: webapp/wiconnect.js.gz to flash file system
Request GET /webapp/wiconnect.js.gz
Connecting (http): 10.5.6.60:5002
HTTP response: 200
Success

Change Log

ModifiedChangesWiConnect Version
Required
2015-03-05Created2.0+