I was able to control a 5V relay in my previous project but while I'm following this example here to try a new approach with my Wemos D1 R1 Module connected to my PC through a USB Cable only.
The code is as follows:
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "SSID "; // your network SSID (name)
char pass[] = "PASS"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
IPAddress server(172,217,19,46); // Google
// Initialize the client library
WiFiClient client;
void setup() {
Serial.begin(115200);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
// don't do anything else:
while(true);
}
else {
Serial.println("Connected to wifi");
Serial.println("\nStarting connection...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.0");
client.println();
}
}
}
void loop() {
}
In my Serial Monitor I'm getting the following messages repeatedly:
18:59:50.109 ->
18:59:50.109 -> ets Jan 8 2013,rst cause:4, boot mode:(3,6)
18:59:50.144 ->
18:59:50.144 -> wdt reset
18:59:50.144 -> load 0x4010f000, len 3584, room 16
18:59:50.144 -> tail 0
18:59:50.144 -> chksum 0xb0
18:59:50.144 -> csum 0xb0
18:59:50.144 -> v2843a5ac
18:59:50.144 -> ~ld
18:59:50.210 -> Attempting to connect to WPA network...
18:59:50.210 -> SSID: Connect4G
I get where the last two readings come from but the rest I have no idea. It seems like it keeps rebooting.