Skip to content

Commit f0171ba

Browse files
committed
2016.02.05.
0 parents  commit f0171ba

25 files changed

+3787
-0
lines changed

Diff for: README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Arduino Library for PHPoC
2+
This library is to use [PHPoC (WiFi) Shield for Arduino](http://www.phpoc.com/phpoc_shield_for_arduino.php).
3+
4+
Available Examples
5+
----------------------------
6+
* ChatServer
7+
* DateTime
8+
* EmailClient
9+
* SSHServer
10+
* SSLServer
11+
* TelnetServer
12+
* WebClient
13+
* WebRemotePush
14+
* WebRemoteSlide
15+
* WebSSLClient
16+
17+
References
18+
----------------------------
19+
* [PHPoC (WiFi) Shield for Arduino Library Reference](http://www.phpoc.com/support/manual/phpoc_shield_for_arduino_library_reference/)
20+
21+
Arduino Library 05

Diff for: examples/ChatServer/ChatServer.ino

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <SPI.h>
2+
#include <Phpoc.h>
3+
4+
PhpocServer server(23);
5+
boolean alreadyConnected = false; // whether or not the client was connected previously
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
while(!Serial)
10+
;
11+
12+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
13+
//Phpoc.begin();
14+
15+
server.begin();
16+
17+
Serial.print("Chat server address : ");
18+
Serial.println(Phpoc.localIP());
19+
}
20+
21+
void loop() {
22+
// wait for a new client:
23+
PhpocClient client = server.available();
24+
25+
// when the client sends the first byte, say hello:
26+
if (client) {
27+
if (!alreadyConnected) {
28+
// clear out the transmission buffer:
29+
client.flush();
30+
Serial.println("We have a new client");
31+
client.println("Hello, client!");
32+
alreadyConnected = true;
33+
}
34+
35+
if (client.available() > 0) {
36+
// read the bytes incoming from the client:
37+
char thisChar = client.read();
38+
// echo the bytes back to the client:
39+
server.write(thisChar);
40+
// echo the bytes to the server as well:
41+
Serial.write(thisChar);
42+
}
43+
}
44+
}

Diff for: examples/DateTime/DateTime.ino

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <SPI.h>
2+
#include <Phpoc.h>
3+
4+
PhpocDateTime datetime;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while(!Serial)
9+
;
10+
11+
Phpoc.begin();
12+
13+
Serial.println("Phpoc Time test");
14+
15+
Serial.print(datetime.year());
16+
Serial.print('-');
17+
Serial.print(datetime.month());
18+
Serial.print('-');
19+
Serial.print(datetime.day());
20+
Serial.print(' ');
21+
Serial.print(datetime.dayofWeek());
22+
Serial.print(':');
23+
Serial.print(datetime.hour());
24+
Serial.print(':');
25+
Serial.print(datetime.minute());
26+
Serial.print(':');
27+
Serial.print(datetime.second());
28+
Serial.println();
29+
30+
datetime.date("Y-m-d H:i:s");
31+
}
32+
33+
void loop() {
34+
Serial.println(datetime.date());
35+
delay(1000);
36+
}

Diff for: examples/EmailClient/EmailClient.ino

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include "SPI.h"
2+
#include "Phpoc.h"
3+
4+
PhpocEmail email;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while(!Serial)
9+
;
10+
11+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
12+
//Phpoc.begin();
13+
14+
Serial.println("Email Client Test");
15+
16+
// setup From/To/Subject
17+
email.setFrom("from_email_address", "from_user_name");
18+
email.setTo("to_email_address", "to_user_name");
19+
email.setSubject("Mail from PHPoC Shield for Arduino");
20+
21+
// write email message
22+
email.beginMessage();
23+
email.println("Hello, world!");
24+
email.println("I am PHPoC Shield for Arduino");
25+
email.println("Good bye");
26+
email.endMessage();
27+
28+
// send email
29+
if(email.send() > 0)
30+
Serial.println("Email send ok");
31+
else
32+
Serial.println("Email send failed");
33+
}
34+
35+
void loop() {
36+
}

Diff for: examples/GmailClient/GmailClient.ino

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "SPI.h"
2+
#include "Phpoc.h"
3+
4+
PhpocEmail email;
5+
6+
void setup() {
7+
Serial.begin(9600);
8+
while(!Serial)
9+
;
10+
11+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);
12+
//Phpoc.begin();
13+
14+
Serial.println("Email Client Test using outgoing relay server");
15+
16+
// [login using your private password]
17+
// Google may block sign-in attempts from some apps or devices that do not use modern security standards.
18+
// Change your settings to allow less secure apps to access your account.
19+
// https://www.google.com/settings/security/lesssecureapps
20+
21+
// [login using app password]
22+
// 1. turn on 2-step verification
23+
// 2. create app password
24+
// 3. apply app password as your login password
25+
26+
// setup outgoing relay server - gmail.com
27+
email.setOutgoingServer("smtp.gmail.com", 587);
28+
email.setOutgoingLogin("your_login_id", "your_login_password or app_password");
29+
30+
// setup From/To/Subject
31+
email.setFrom("from_email_address", "from_user_name");
32+
email.setTo("to_email_address", "to_user_name");
33+
email.setSubject("Mail from PHPoC Shield for Arduino");
34+
35+
// write email message
36+
email.beginMessage();
37+
email.println("Hello, world!");
38+
email.println("I am PHPoC Shield for Arduino");
39+
email.println("Good bye");
40+
email.endMessage();
41+
42+
// send email
43+
if(email.send() > 0)
44+
Serial.println("Email send ok");
45+
else
46+
Serial.println("Email send failed");
47+
}
48+
49+
void loop() {
50+
}

Diff for: examples/SSHServer/SSHServer.ino

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "SPI.h"
2+
#include "Phpoc.h"
3+
4+
PhpocServer server(22);
5+
boolean alreadyConnected = false; // whether or not the client was connected previously
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
while(!Serial)
10+
;
11+
12+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
13+
//Phpoc.begin();
14+
15+
server.beginSSH("root", "1234");
16+
//server.beginSSH("", "");
17+
//server.beginSSH();
18+
19+
Serial.print("SSH server address : ");
20+
Serial.println(Phpoc.localIP());
21+
}
22+
23+
void loop() {
24+
// wait for a new client:
25+
PhpocClient client = server.available();
26+
27+
// when the client sends the first byte, say hello:
28+
if (client) {
29+
if (!alreadyConnected) {
30+
// clear out the transmission buffer:
31+
client.flush();
32+
Serial.println("We have a new client");
33+
client.println("Hello, client!");
34+
alreadyConnected = true;
35+
}
36+
37+
if (client.available() > 0) {
38+
// read the bytes incoming from the client:
39+
char thisChar = client.read();
40+
// echo the bytes back to the client:
41+
server.write(thisChar);
42+
// echo the bytes to the server as well:
43+
Serial.write(thisChar);
44+
}
45+
}
46+
}

Diff for: examples/SSLServer/SSLServer.ino

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "SPI.h"
2+
#include "Phpoc.h"
3+
4+
PhpocServer server(443);
5+
boolean alreadyConnected = false; // whether or not the client was connected previously
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
while(!Serial)
10+
;
11+
12+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
13+
//Phpoc.begin();
14+
15+
server.beginSSL();
16+
17+
Serial.print("SSL server address : ");
18+
Serial.println(Phpoc.localIP());
19+
}
20+
21+
void loop() {
22+
// wait for a new client:
23+
PhpocClient client = server.available();
24+
25+
// when the client sends the first byte, say hello:
26+
if (client) {
27+
if (!alreadyConnected) {
28+
// clear out the transmission buffer:
29+
client.flush();
30+
Serial.println("We have a new client");
31+
client.println("Hello, client!");
32+
alreadyConnected = true;
33+
}
34+
35+
if (client.available() > 0) {
36+
// read the bytes incoming from the client:
37+
char thisChar = client.read();
38+
// echo the bytes back to the client:
39+
server.write(thisChar);
40+
// echo the bytes to the server as well:
41+
Serial.write(thisChar);
42+
}
43+
}
44+
}

Diff for: examples/TelnetServer/TelnetServer.ino

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "SPI.h"
2+
#include "Phpoc.h"
3+
4+
PhpocServer server(23);
5+
boolean alreadyConnected = false; // whether or not the client was connected previously
6+
7+
void setup() {
8+
Serial.begin(9600);
9+
while(!Serial)
10+
;
11+
12+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
13+
//Phpoc.begin();
14+
15+
// beginTelnet() enables telnet option negotiation & "character at a time".
16+
// In "character at a time" mode, text typed is immediately sent to server.
17+
server.beginTelnet();
18+
19+
Serial.print("Telnet server address : ");
20+
Serial.println(Phpoc.localIP());
21+
}
22+
23+
void loop() {
24+
// wait for a new client:
25+
PhpocClient client = server.available();
26+
27+
// when the client sends the first byte, say hello:
28+
if (client) {
29+
if (!alreadyConnected) {
30+
// clear out the transmission buffer:
31+
client.flush();
32+
Serial.println("We have a new client");
33+
client.println("Hello, client!");
34+
alreadyConnected = true;
35+
}
36+
37+
if (client.available() > 0) {
38+
// read the bytes incoming from the client:
39+
char thisChar = client.read();
40+
// echo the bytes back to the client:
41+
server.write(thisChar);
42+
// echo the bytes to the server as well:
43+
Serial.write(thisChar);
44+
}
45+
}
46+
}

Diff for: examples/WebClient/WebClient.ino

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <SPI.h>
2+
#include <Phpoc.h>
3+
4+
//char server_name[] = "www.google.com";
5+
//char server_name[] = "216.58.221.36";
6+
char server_name[] = "www.arduino.cc";
7+
PhpocClient client;
8+
9+
void setup() {
10+
Serial.begin(9600);
11+
while(!Serial)
12+
;
13+
14+
Serial.println("PHPoC TCP Client test");
15+
16+
Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
17+
//Phpoc.begin();
18+
19+
if(client.connect(server_name, 80))
20+
{
21+
Serial.println("connected");
22+
client.println("GET / HTTP/1.0");
23+
client.println();
24+
}
25+
else
26+
Serial.println("connection failed");
27+
}
28+
29+
void loop() {
30+
if(client.available())
31+
{
32+
char c = client.read();
33+
Serial.print(c);
34+
}
35+
36+
if(!client.connected())
37+
{
38+
Serial.println("disconnected");
39+
client.stop();
40+
while(1)
41+
;
42+
}
43+
}

0 commit comments

Comments
 (0)