Difference between revisions of "Internet Application Guide"

From Flowcode Help
Jump to navigationJump to search
 
(16 intermediate revisions by the same user not shown)
Line 28: Line 28:
 
|+Hardware Setup
 
|+Hardware Setup
 
|-
 
|-
 +
|
 
|EB006
 
|EB006
 
|PICmicro multiprogrammer
 
|PICmicro multiprogrammer
 
|-
 
|-
 +
|Port A
 
|EB005
 
|EB005
 
|E-blocks LCD board
 
|E-blocks LCD board
|Port A
 
 
|-
 
|-
 +
|Port B
 
|EB004
 
|EB004
 
|E-blocks LED board
 
|E-blocks LED board
|Port B
 
 
|-
 
|-
 +
|Port C
 
|EB023
 
|EB023
 
|E-blocks Internet board
 
|E-blocks Internet board
|Port C
 
 
|-
 
|-
 +
|Port D
 
|EB007
 
|EB007
 
|E-blocks push-to-make switch board
 
|E-blocks push-to-make switch board
|Port D
 
 
|}
 
|}
 
  
 
== Example 1: Embedded web server with dynamic content ==
 
== Example 1: Embedded web server with dynamic content ==
Line 53: Line 53:
 
{{Fcfile|Apps_Internet_Ex1_Webserver.fcfx| Embedded Web Server Example}}
 
{{Fcfile|Apps_Internet_Ex1_Webserver.fcfx| Embedded Web Server Example}}
  
Example 1 demonstrates use of the Flowcode Webserver component. The server is initialised and then the program enters a infinite loop where the value of the switch E-Block is read into variable BOO1 and subsequently viewed in a browser. The CheckSocketActivity macro function must be called as part of the main program loop as this allows remote page requests to be detected and serviced.
+
Example 1 demonstrates use of the Flowcode Webserver component. The server is initialised and then the program enters an infinite loop where the value of the switch E-Block is read into variable BOO1 and subsequently viewed in a browser. The CheckSocketActivity macro function is called as part of the main program loop and this allows remote page requests to be detected and serviced.
 +
 
 +
Please note that due to limitations with use if RAM storage on some processors you will need to ensure that each line of the page text (HTML) is quite short, usually below 100 characters.
 +
Otherwise this can cause an error such as “Error: No remaining RAM block (on target) big enough for:”
  
 
The web server component properties will need to be adjusted for your network before the example is compiled and downloaded to the target embedded hardware.
 
The web server component properties will need to be adjusted for your network before the example is compiled and downloaded to the target embedded hardware.
Line 59: Line 62:
 
[[File:TCPIP_Settings.png]]
 
[[File:TCPIP_Settings.png]]
  
The default settings are shown above, where 192.168.1.111 is the IP address of the embedded web server.
+
The example program settings are shown above, where 192.168.1.111 is the IP address of the embedded web server.
 +
 
  
 
The port used for the listening socket is set in the program via the CreateServerSocket macro, as below.
 
The port used for the listening socket is set in the program via the CreateServerSocket macro, as below.
Line 67: Line 71:
 
Hence the url for your browser with these settings would be <nowiki>http://192.168.1.111:88</nowiki>
 
Hence the url for your browser with these settings would be <nowiki>http://192.168.1.111:88</nowiki>
  
Additionally the sever can be run in simulation, in which case the server pages can be accessed either on the localhost (127.0.0.1:88) or remotely from the host IP address.
+
 
 +
Additionally the server can be run in simulation, in which case the server pages can be accessed either on the localhost (127.0.0.1:88) or remotely using the host IP address.
 +
 
 +
You may need to remove firewall restrictions.
 +
 
 +
[[File:SwitchMonitor.png]]
 +
 
 +
 
 +
Dynamic content is achieved by using the SetOutValue(index, string) macro of the Webserver component. This macro takes the index (maximum 4) and the string value as parameters. The string value then replaces a particular escape sequence, starting with a %, found in the html source.
 +
 
 +
For example: If the html source contains "hello this is %1", a call to SetOutValue(1, "my text") will produce "hello this is my text" at the browser.
 +
 
 +
== Example 2: Ping protocol using the TCP/IP component ==
 +
 
 +
{{Fcfile|Apps_Internet_Ex2_Ping.fcfx| Network Ping Example}}
 +
 
 +
Example 2 uses the Flowcode TCP/IP component and creates a simple ping system that can be used to detect if a particular IP address is being used on a network. This is useful to allow you to scan for computers on a network or simply to ensure an address is valid before we start sending data to it.
 +
 
 +
 
 +
 
 +
== Example 3: Interactive web server using the TCP/IP component ==
 +
 
 +
{{Fcfile|Apps_Internet_Ex3_TCPIP.fcfx| Interactive Web Server Example}}
 +
 
 +
Example 3 demonstrates the lower level components of a web server, where we parse the incoming requests, send html to a web browser and also display the incoming request data to the LCD.

Latest revision as of 09:50, 22 June 2015

Introduction

These examples demonstrate Internet technologies, including web servers, HTTP, TCPIP and other protocols, using E-blocks and Flowcode V6 components.

In particular they make use of the EB023 E-blocks Internet board, connected to an EB006 E-blocks PICmicro multiprogrammer fitted with a 16F1937 microprocessor.

However, the examples are easily changed in Flowcode to support other microprocessors and platforms.

The Matrix TSL EB566SI6 Easy Internet bundle has all the items required for these sample applications and is an ideal introduction to Internet protocols and technologies.


Setting up the project hardware

Connect the E-Blocks as indicated in the table below.

The Internet, LCD and Switch E-Blocks all need to be powered via wire connections to the +V on the EB006.

In addition, the EB023 Internet board requires the Vpwr terminal connecting to the Vpwr (or +14V) terminal of the EB006.

Connect an Ethernet cable from the EB023 to the RJ45 socket of your computer or router. In the case of connecting to a PC use an Ethernet cross-over cable.


Hardware Setup
EB006 PICmicro multiprogrammer
Port A EB005 E-blocks LCD board
Port B EB004 E-blocks LED board
Port C EB023 E-blocks Internet board
Port D EB007 E-blocks push-to-make switch board

Example 1: Embedded web server with dynamic content

FC6 Icon.png Embedded Web Server Example

Example 1 demonstrates use of the Flowcode Webserver component. The server is initialised and then the program enters an infinite loop where the value of the switch E-Block is read into variable BOO1 and subsequently viewed in a browser. The CheckSocketActivity macro function is called as part of the main program loop and this allows remote page requests to be detected and serviced.

Please note that due to limitations with use if RAM storage on some processors you will need to ensure that each line of the page text (HTML) is quite short, usually below 100 characters. Otherwise this can cause an error such as “Error: No remaining RAM block (on target) big enough for:”

The web server component properties will need to be adjusted for your network before the example is compiled and downloaded to the target embedded hardware.

TCPIP Settings.png

The example program settings are shown above, where 192.168.1.111 is the IP address of the embedded web server.


The port used for the listening socket is set in the program via the CreateServerSocket macro, as below.

Server Socket Port.png

Hence the url for your browser with these settings would be http://192.168.1.111:88


Additionally the server can be run in simulation, in which case the server pages can be accessed either on the localhost (127.0.0.1:88) or remotely using the host IP address.

You may need to remove firewall restrictions.

SwitchMonitor.png


Dynamic content is achieved by using the SetOutValue(index, string) macro of the Webserver component. This macro takes the index (maximum 4) and the string value as parameters. The string value then replaces a particular escape sequence, starting with a %, found in the html source.

For example: If the html source contains "hello this is %1", a call to SetOutValue(1, "my text") will produce "hello this is my text" at the browser.

Example 2: Ping protocol using the TCP/IP component

FC6 Icon.png Network Ping Example

Example 2 uses the Flowcode TCP/IP component and creates a simple ping system that can be used to detect if a particular IP address is being used on a network. This is useful to allow you to scan for computers on a network or simply to ensure an address is valid before we start sending data to it.


Example 3: Interactive web server using the TCP/IP component

FC6 Icon.png Interactive Web Server Example

Example 3 demonstrates the lower level components of a web server, where we parse the incoming requests, send html to a web browser and also display the incoming request data to the LCD.