M5Stack WiFi Test
- 2018/09/28
- 11:15
M5Stack WiFi Test
Hello everyone! I’m RoboTakao.
I have not tested whether WiFi works properly with M5Stack, so I tested WiFi using sample sketches.
File -> Sketch example -> WiFi -> WiFiClient

Change the following part of the sketch.
const char* ssid = "your-ssid"; <- Enter the SSID of your environment.
const char* password = "your-password"; <- Enter the password for your environment.

Compile and write it.
As you start sketch and look at the serial monitor you can see that it is moving.
An IP address was given. M5Stack is connected to the server of sparkfun.

Sample Sketch
/*
* This sketch sends data via HTTP GET requests to data.sparkfun.com service.
*
* You need to get streamId and privateKey at data.sparkfun.com and paste them
* below. Or just customize this script to talk to other HTTP servers.
*
*/
#include
const char* ssid = "your-ssid";
const char* password = "your-password";
const char* host = "data.sparkfun.com";
const char* streamId = "....................";
const char* privateKey = "....................";
void setup()
{
Serial.begin(115200);
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
int value = 0;
void loop()
{
delay(5000);
++value;
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
// We now create a URI for the request
String url = "/input/";
url += streamId;
url += "?private_key=";
url += privateKey;
url += "&value=";
url += value;
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
// Read all the lines of the reply from server and print them to Serial
while(client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
Good Bye! Thank you.
M5Stack related posts
1) M5Stack Arduino IDE initial setting (macOS)
2) M5Stack I tried Arduino IDE sample sketches
3) M5Stack I treid Avatar(Arduino IDE)
4) M5Stack LED Blink
5) M5Stack Servo operating
6) M5Stack X 16ch Servo Driver PCA9685
7) M5Stack Bluetooth Low Energy (BLE) Test
スポンサードリンク