Example Applications

From NetBurner Wiki

Jump to: navigation, search

This is a list of all NetBurner example applications. These applications can be found in your c:\nburn\examples directory.

Contents

AES

Advanced Encryption Standard Example

A basic description of AES can be obtained from wikipedia, and if you are new to AES, you should definitely do some research to understand the implementation. The description below is from wikipedia:

In cryptography, a block cipher is a symmetric key cipher which operates on fixed-length groups of bits, termed blocks, with an unvarying transformation. When encrypting, a block cipher might take a (for example) 16-bit block of plaintext as input, and output a corresponding 16-bit block of ciphertext. The exact transformation is controlled using a second input — the secret key. Decryption is similar: the decryption algorithm takes, in this example, a 16-bit block of ciphertext together with the secret key, and yields the original 16-bit block of plaintext.

To encrypt messages longer than the block size, a mode of operation is used. Block ciphers can be contrasted with stream ciphers; a stream cipher operates on individual digits one at a time, and the transformation varies during the encryption. The distinction between the two types is not always clear-cut: a block cipher, when used in certain modes of operation, acts effectively as a stream cipher.

This example demonstrates how to use the AES key, encryption, and decryption function calls on a 16 byte block of data. Since AES is a block cipher, all data must be encrypted in 16 byte blocks. If you have more than 16 bytes to transfer, you must break the data into 16 byte blocks, encrypt them (you can use the same key for all blocks), send them, then decrypt them in 16 byte blocks on the other end.

AutoUpdateFeatures

NetBurner AutoUpdate Features Example

The purpose of this example is to demonstrate the following three features of AutoUpdate that are available to the programmer:

1. update_authenticate_func / ipsetup_authenticate_func

If these function pointers are set to point at a function of the form: int YourFunc(const char * name , const char * password); Then the system will indicate to the update requester that a Password is needed. It will then request the password from the other end. It will also call this function with the passed in password and name. If they are OK Return a 1 otherwise return a 0. It will do this in an unsecure fashion (The password is in the TCP stream) If you need a more secure system it needs to be converted to a challenge/response system that would have significantly more impact on the code size.


2. update_shutdown_func

If this function pointer is set to point at a function of the form: int YourFunc(void); Then the system will call this function to shutdown the system before it updates the code. If this function returns a 0 then the update will be aborted.


3. watchdog_service_function

If this function pointer is set to point at a function of the form: void YourFunc(void); Then the system will call this function throughout the AutoUpdate/TCPUpdate process to make sure that the watchdog timer is serviced.

DeviceName

Assiging a DNS name to a NetBurner device.

When a network device (such as the NetBurner module) requests an IP address from a DHCP Server, the device sends it MAC address and an optional device name (this is supported by your NetBurner device). The DHCP Server supplies the dynamic IP address and maintains a table containing the MAC address, IP address and device name for each device that has accepted a DHCP lease.

The purpose of a DNS server is to convert a name into an IP address. To do this it must get the information from your DHCP Server. On windows server platforms that run both a DHCP server and DNS server, this can be configured in a dialog box. On liniux/unix it may be more complicated. Basically, every time the DHCP server gives out a new dynamic IP address it updates the DNS server. If you are not using DHCP, and are assigning static IP addresses, then you must update the DNS server with the entries manually (ie name and IP address).

If you do not have a DNS server, you can modify the lmhosts file on your PC to add the IP address and name of each network device you want to address by name. You would need to do this on every PC that wants to use the name.

Windows has a proprietary protocol called WINS (only microsoft products can use it). Windows machines can have a name, and the protocol enables windows machines to talk to one another. This is achieved by having one windows PC maintain the table of MAC address, IP address and names.

DNS

EFFS

Examples using the Flash File system

EFFS-AppUpdate

EFFS-BASIC

EFFS-FTP

EFFS-HTTP

Email

Examples sending emails and attachments

SendMail

SendMailAttach

SendMailAttachEFFS

ExceptionTryCatch

Fdprintf

This program illustrates how to use a file descrptor printf() function, named fdprintf(). The function takes the form of

fdprintf( int fd, const char *format )

where

fd = Valid serial or network file descriptor
*format = printf() style variable argument format string.

Example:

fdprintf( fd, "Seconds since system boot: %ld\r\n", Secs ); 

The example application also includes an optional serial initialization function that illustrates how to open the serial ports in interrupt driven mode, and how to assign stdio to a file descriptor.

FTP

Examples using FTP as a client and a server

FTP_Client

FTP Client Example Program

This program will run a FTP Client program on the NetBurner board to do the following:

  • Connect to a FTP Server
  • Change to a remote directory called "test1"
  • Obtain a directory listing and print the listing to stdout
  • Create a file on the FTP Server called FOOBAR.TXT
  • Read back contents of FOOBAR.TXT and send to stdout

FTPD_AppUpdate

The "FTPD code update" Example Program

This program is an example of how you can use the FTP server to allow application firmware updates via FTP.

FTPD_ExposeHtml

Expose html ftp server sample.

This sample exposes all of the files that were in your project's html subdirectory as a read only file system for your FTP viewing pleasure. This is an advanced application and requires in depth knowledge of FTP and FTP applications. A significant part of the complexity involved concerns navigating and displaying file names and directories.

FTPD_Trivial

The "Trivial" FTP Server Example.

This example will create an FTP Server running on the NetBurner board. The FTP Server will start up and wait for a FTP client connection. The FTP Server provides two functions:

  1. Allows the FTP Client to download a single file, which has fixed content. After downloading, you can view this file on your host computer.
  2. Allows the FTP Client to upload an ASCII text file. The file is not stored in memory, but is sent out the Com1 serial port so you can see it with a serial terminal program like MTTTY.

GDBdemo

This is a very simple application to run with the debugger on a NetBurner network-enabled hardware platform. The application will boot and stay in a while() loop that increments the LED display on the NetBurner MOD-DEV-100 development board.

Linkstatus

Multicast

Newdemo

NTPClient

A simple NTP Client example that will get the time from a NTP server and display the UTC and PDT time through the debug serial port. Use MTTTY to monitor the output. For this example to function, your NetBurner device must have access to the Internet, with a working configuration for the IP address, mask and gateway.

Parallax

Parallax basic stamp network interface application for the SB70.

This program provides a web, ftp and serial interface to Parallax Basic Stamp products. It includes the ability to create web pages with variables, and the ability to download those web pages via and ftp interface. Interaction between the basic stamp and NetBurner web interface is accomplished through the serail port interface.

PPP

This PPP example shows how to setup and use a modem for a PPP connection. It demonstrates:

  • Dialing in to a Netburner using a PPP client. (Like Window dial up networking)
  • Dialing out to an ISP.
  • Sending E-Mail from a Netburner.

There are two types of high level connections that can be made with PPP is either direct or modem. A direct connection is ussually performed with only a serial cable connection and will jump right into the PPP negotiations with the host or client. A modem connection is one where there is a modem between the PC and NetBurner. The modem PPP functions will send AT commands before any PPP negotiation to initialize the modem.

Note: When setting up a NetBurner to be a Direct connect server with a Windows XP machine a special loop back adapter must be used on the serial cable going to the PC. This cable can be made manually by tying pin 1 to pin 4 on the DB9 serial cable to properly loop back the carrier detect signal. This cable is not required if the Windows XP machine is configured to be the direct connect server. Software flow control should also be disabled on both the NetBurner and XP configurations. These configurations might also apply to any other devices, or OSs, that make a PPP direct connection to a NetBurner.

RTOS

Examples using operating system functions

OSCrit

This example will show how to create critical sections with the standard C type function calls OSCritEnter() and OSCritLeave(), and compare them to the the C++ object type which eliminates the problem of matching each OSCritEnter() to a corresponding OSCritLeave().

While this example is trivial with only a simple global variable, critical sections need to be used for objects, such as linked lists, that could be changed by multiple tasks. In such cases, each task would use a critical section to ensure the modifications could be completed before a task switch occurred.

OSFifo

FIFO Example Program

This program creates two tasks and a FIFO. Messages are sent from one task to another using the FIFO. A timeout value for the pend function is used to illustrate the timeout feature of the FIFO.

OSFlags

This example illustrates how OSFlags can be used to pend on multiple events. UserMain creates 3 tasks, each of which will set a OSFlag after a time delay of some number of seconds. UserMain will then pend and block until ANY of the 3 flags are set. You can also modify the example to pend until ALL of the 3 flags are set.

OSMultiTaskUserInput

Multiple task user input example.

This program illustrates how to create a task and use a mailbox to accept user input from a serial port.

  • UserMain task will wait pend on a mailbox for user input
  • UserInput task will block waiting for a user to type in data from the serial port
  • This example also illustrates how to terminate a task

OSSemaphore

Semaphore Example Program This program will create 2 tasks and a semaphore. The UserMain task will block for a semaphore posted from MyTask. The output for this example is displayed through the serial debug port, which can be viewed with the MTTTY program.

Sampleapp

This example is the smallest possible C "Hello World". As such, it does not support the autoupdate or network download capability as do the other examples. Once you have loaded this example application, you will need to perform a serial download through the debug serial port to put a different application in your NetBurner device.

SaveUserParameters

This example program illustrates how you can use the User Parameter sector of on-chip Flash memory to save/retrieve up to 8k bytes of data. The on-chip memory is different than the Flash SD card interface. The API function calls SaveUserParameters() and GetUserParameters() are an easy way to store small amounts of non-volatile data.

This example was written to run on the Mod5234/70/72/82 or SB70/72. Please refer to your platform documentation \nburn\docs\platform, for the storage size of other platforms. There are also application notes on how you may expand the amount of on-chip storage in the support section of the NetBurner home page

Serial

Examples using the UART Serial port

DualTcpToSerial

This sample application connects two serial ports to two different TCP ports, and continuously transfers data between them. In other words, you have a dual serial-to-ethernet device. An easy way to test this operation is to open two telnet sessions and two MTTTY sessions as shown below. To start a telnet session on a windows pc, open a command prompt and type

telnet 10.1.1.2 2000

where you would replace 10.1.1.2 with the IP address of your netburner device.

Telnet on port 2000 >-----------< MTTTY on serial port 0
Telnet on port 2001 >-----------< MTTTY on serial port 1

Now anything you type in the first telnet session will be sent to serial port 0, and vice versa. Anything you type in the second telnet session will be sent to serial port 1 and vice versa.

SB72App

This program is designed to connect a RS-232 device to a network. It basically opens a serial port and an Ethernet port, then connect them. This allows any data sent to the Ethernet port to be forwarded to the serial port, and vice versa.

  • Only 1 connection is allowed at a time. Additional client connections will be queued, and serviced as the active connection completes.
  • Override Timeout: When a new TCP connection is attempted while there is already an active connection, one of 3 actions can be taken:
  1. Don't ever disconnect the active connection.
  2. Only disconnect the existing connection if it has been idle for x seconds. Configure "Allow new connection...." to the number of seconds.
  3. Always disconnect the existing connection. Configure "Allow new connection...." to 0.

SerialBurner

This program is designed to connect a RS-232 device to a network. It basically opens a serial port and an Ethernet port, then connect them. This allows any data sent to the Ethernet port to be forwarded to the serial port, and vice versa.

WARNINGS When compiling, remember to delete iprintf("Done") and iprintf("Get") in http.cpp. Otherwise, the data will be sent out the serial port when the web page is used.

SerialToSerial

This simple program opens both serial ports and sends data from one to another using the select() function, which can pend on multiple file descriptors at one time. Essay papers

The serial ports are initialized by the monitor in polled mode. To enable buffered interrupt driven mode, the serial ports are closed and then reopened with OpenSerial().

TCP2serial

This program opens a serial port and an TCP port and connects them. It does this with no flow control, or char mapping.

Syslog

The Syslog utility enables you to send logging information to a destination host computer using UDP (port number 514). This example uses syslog to send a simple counting variable to a host computer.

To run the example:

  1. Verify you have proper network communication with you NetBurner device. It must have an IP address and mask.
  2. Modify the source code line: SysLogAddress = AsciiToIp("10.1.1.191"); so that it specifies the address of your computer. If this line is commented out and no SysLogAddress is specified, then the syslog data will be sent as a UDP broadcast.
  3. Run the NetBurner "UDP Terminal Tool" application. Make sure the local listening port field is set to 514, the default syslog port.
  4. Download and run the application on your NetBurner device.

TCP

Examples using TCP as a connection type

TcpClientSimple

TcpMultiSocket

TcpServerSelect

TcpServerSimple

TcpSpeedTest

TcpStressTest

Telnetcmd

TFTP

TFTP Example Program

This example program will use a NetBurner device to communicate with the NetBurner TFTP Server running on a PC. To run the example:

  1. The TFTP Server on the PC must be started and configured to handle both reads and writes.
  2. You must specify the TFTP server in the NetBurner device using IPSetp or through the monitor

UDP

Examples using UDP as a connection type

Java

This is a UDP echo server that runs on your PC. You will need the JAVA SDK to build this code. The application will listen on a port for incomming UDP packets, and then echo them back to the sender.

UDPPacketClass

UDP Packet C++ Class Example

This application will send/receive UDP packets with another host on a network, such as a PC. Use the MTTTY serial port program to access the menu and prompts to specify the destination IP address and port number.

NetBurner supplies an API for handling UDP as a C++ Class using UDPPacket, or you can use a UDP sockets API (see UDP socket example).

For an external UDP host you can use the NetBurner java example, or the NetBurner UDP terminal program.

UDPSendReceive

NetBurner simple UDP send/receive example.

This example program will allow you to send and receive UDP packets to another device or host computer. To run the example, connect a serial port to the debug serial port on your NetBurner device and run a dumb terminal program such as MTTTY. On the PC, run the NetBurner UDP Terminal (be sure to set the IP address and port numbers to match). You will then be able to type characters in the UDP Termainal and see them in MTTTY, and vice versa.

You will be prompted for the port number to send/receive data and the destination IP address of the other device or host. Note that the application uses the same port number to send and receive data, but you can change this to any other port number you wish.

The application will create a thread to recive packets and display them on the debug port, while the main task will take any data you type in to the MTTTY dumb terminal and send it as a udp packet to the destination IP address.

UDPSockets

UDP Sockets Example

This application will send/receive UDP packets with another host on a network, such as a PC. Use the MTTTY serial port program to access the menu and prompts to specify the destination IP address and port number.

NetBurner supplies an API for handling UDP as a C++ Class using UDPPacket, or you can use a UDP socets API (see UDP socet example).

For an external UDP host you can use the NetBurner java example, or the NetBurner UDP terminal program.

Web

Examples featuring HTTP and web interfaces

BarGraph

The BarGraph example demonstrates how to create dynamic GIF images and how to process HTML Forms. The user is presented with a HTML page and can dynamically change the GIF images displayed on the web page.

FilePost

Multipart Form Example.

A multipart form enables a web browser to upload a file to a web server. In order to enable file uploads on an embedded platform with limited memory, you must specify the maximum file size that can be uploaded. This is done with the EnableMultiPartForms() function, which must be called before any uploads can occur.

This example presents a web page with a field for selecting a file to upload to the NetBurner device. When the "Send File" button is selected, the upload is performed. The uploaded file is then displayed on the web page.

FlashForm

The FlashForm example demonstrates how to create dynamic HTML web pages, process HTML Forms, and store data in Flash memory. The user is presented with an HTML page that shows a stored message that is retrieved from Flash memory. The user can then submit new messages and store them in Flash.

HtmlCookie

HTML Cookie Example Program

This example shows how to implement cookies with the NetBurner web server. The example program works as follows:

  • Three web pages are created: an index page, a page to set the cookie value to "MyCookie", and a page to view the cookie value.
  • When you run the program open a web browser and go to the index page.
  • Select the "set cookie" link to set the cookie. Note that if you select "show cookie" before setting the value, no value will be displayed.
  • Select the "show cookie" link to view the cookie

A cookie will apply to a "site". In this example a "site" will probably be the IP address of your NetBurner device. The cookie will be sent as part of the HTML header for any page requested from the "site".

HtmlPassword

HtmlVariables

This example illustrates how to use dynamic HTML content with variables and function call parameters embedded in HTML code. The HTML tags VARIABLE and FUNCTIONCALL enable you to display application variables and call application functions directly from the HTML code.

Note for NBEclipse Users: This example requires that the autogenerated file htmldata.cpp have a path to include the htmlvar.h header file. To add the path in NBEclipse:

  • Right-click on your project and select properties
  • Select "C/C++ Build" options
  • Select "GNU C++ Compiler" -> Directories
  • Use the "+" in the include path box to add the project's "HtmlVariables\html" folder to the list of include paths.

PostApplicationUpdate

This example demonstrates how you can update your NetBurner device application image from a web page, using MultiPart Forms. The POST handler will process the incoming application file and reprogram the NetBurner device's application flash memory. If the reboot checkbox was checked, it will reboot the NetBurner device.

SimpleHtml

The SimpleHTML project is a very basic example that hosts a web page on the NetBurner device. This web page displays strictly text.

TicTacToe

The TicTacToe example is a multipurpose application. It demonstrates:

  • Multiple Page Dynamic HTML.
  • HTML generation beyond simple fill-in's.
  • Keeping state from page to page in the URL.
  • A Command dispatcher using both the serial and Telnet ports.
  • The NetBurner Diagnostic functions.
  • ICMP Ping under program control.

This is accomplished with a number of simple applications.

  • Tic Tac Toe game.
  • Manipulate LEDs
  • Example of a meta tag to create a "reloading web page", which refreshes itself at 1 second intervals.

Wifi_infrastructure

Wifiadhoc