Web content is a HTML file and printed to serial monitor.
Hardware Required
- Arduino Uno or Mega
- USB Cable for Arduino
- PHPoC Shield (P4S-347) or PHPoC WiFi Shield (P4S-348)
Circuit
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino Uno or Mega
Note that: Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT be used for general I/O.
Install Arduino IDE
If you have not install Arduino IDE yet, please download and install Arduino IDE .
Install Library
- Run Arduino IDE.
- Navigate to Sketch > Include Library > Manage Libraries
- Search "Phpoc" on search bar of the Library Manager.
- Select the PHPoC library and press the [Install] button.
- Restart Arduino IDE for the next step.
Setup Network Information
This part is needed only for the first use.
1. If Ethernet is used
In case of using PHPoC Shield (P4S-348), you have two options to connect to network: Ethernet or WiFi.
If using Ethernet, please follow this instruction to connect the shield to Ethernet.
2. If WiFi is used
WiFi is available in both P4S-347 and P4S-348. Please follow:
- This instruction to access the setup page.
- This instruction if you want to connect shield to WLAN router or Access Point (AP)
- This instruction if you want to operate shield as Access Point (AP)
Enable IPv6 on PHPoC Shield
Go to setup page of PHPoC Shield, enable IPv6 and save.

Note that: In order to connect to IPv6, your LAN/WLAN network MUST support IPv6.
Source Code
- Open "WebClientIPv6" example on Arduino IDE
Code:// Arduino IPv6 web client - GET request for hello.php or logo.txt // // PHPoC Shield and PHPoC WiFi Shield are Internet Shields for Arduino Uno and // Mega. // // This is an example of using Arduino Uno/Mega and PHPoC [WiFi] Shield to make // an HTTP request to a IPv6 web server and get web content in response. Web // content is a HTML file and printed to serial monitor. // // Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on // the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT // be used for general I/O. // // This example code was written by Sollae Systems. It is released into the // public domain. // // Tutorial for the example is available here: // https://forum.phpoc.com/articles/tutorials/1240-arduino-ipv6-web-client #include <Phpoc.h> // hostname of ipv6 web server: char server_name[] = "example.phpoc.com"; PhpocClient client; void setup() { Serial.begin(9600); while(!Serial) ; Serial.println("Sending GET request to IPv6 web server"); // initialize PHPoC [WiFi] Shield: Phpoc.begin(PF_LOG_SPI | PF_LOG_NET); //Phpoc.begin(); // initialize IPv6: Phpoc.beginIP6(); // connect to IPv6 web server on port 80: if(client.connect(server_name, 80)) { // if connected: Serial.println("Connected to server"); // make a HTTP request: //client.println("GET / HTTP/1.0"); client.println("GET /asciilogo.txt HTTP/1.0"); //client.println("GET /remote_addr/ HTTP/1.0"); client.println("Host: example.phpoc.com"); client.println(); } else // if not connected: Serial.println("connection failed"); } void loop() { if(client.available()) { // if there is an incoming byte from the server, read them and print them to // serial monitor: char c = client.read(); Serial.print(c); } if(!client.connected()) { // if the server's disconnected, stop the client: Serial.println("disconnected"); client.stop(); // do nothing forevermore: while(true) ; } }
- The line-by-line explaination of code is presented inside the code.
For more detail of functions's reference, please refer to PHPoC Shield for Arduino Library Reference
Test and Result
An URL includes two parts: hostname and pathname. For example, in URL: "example.phpoc.com/index.php" , hostname is "example.phpoc.com" and pathname is the remaining part "index.php". When accessing via a web browser, we should add:
- "http://" before URL if we want to use HTTP,
- "https://" before URL if we want to use HTTPS.
Now, let's see the default code and modify it.
Default Code: Making HTTP request to http://example.phpoc.com/asciilogo.txt
- In this example code, hostname "example.phpoc.com", and pathname is "asciilogo.txt". Therefore, URL is "example.phpoc.com/asciilogo.txt".
- Compile the example code and upload to Arduino by clicking "Upload" button on Arduino IDE
- Open Serial Monitor tool on Arduino IDE to see the output log:
It is content of a text file that contains PHPoC icon. - Access http://example.phpoc.com/asciilogo.txt via a web browser. Make sure that you enable IPv6 in your PC or devices that you use web browser.
- We can see that HTML in Web Browser and HTML in Serial Monitor are the same.
Modify Code 1: Making HTTP request to http://example.phpoc.com
- Comment line 47 and 48
- Uncomment line 46
In this case, hostname "example.phpoc.com", and pathname is "". Therefore, URL is "example.phpoc.com/". - Compile the example code and upload to Arduino.
- See log in Serial Monitor.
Output log is in HTML format. It is content of web page. - Access http://example.phpoc.com/ via a web browser and view page source (mouse right-click -> view page source)
- We can see that HTML in Web Browser and HTML in Serial Monitor are similar. There are some differences on dynamic data (such as time...)
Modify Code 2: Making HTTP request to REST API via http://example.phpoc.com/remote_addr
- Comment line 46 and 47
- Uncomment line 48
In this case, hostname "example.phpoc.com", and pathname is "". Therefore, URL is "example.phpoc.com/". - Compile the example code and upload to Arduino.
- See log in Serial Monitor.
Output log is the return result of REST API. This REST API returns the IPv6 address of PHPoC Shield. - Access http://example.phpoc.com/remote_addr via a web browser
- We can see that return result in Web Browser and in Serial Monitor are the same.
Change URL of Web Server as you want to.
See Also
- Arduino - TCP Chat Server
- Arduino - TCP IPv6 Chat Server
- Arduino - Telnet Server
- Arduino - SSH Server
- Arduino - SSL Server
- Arduino - Email Client
- Arduino - Gmail Client
- Arduino - Web Client
- Arduino - IPv6 Web Client
- Arduino - SSL Web Client
- Arduino - SSL IPv6 Web Client
- Arduino - Web Server - Remote Push
- Arduino - Web Server - Remote Slide
- Arduino - Web Server - Remote Pad
- Arduino - Web Serial Plotter
- Arduino - Web Serial Monitor
- Arduino - RTC Date and Time
References