In this assignment I choosed to work with ESP8266 to implement networking using wireless, where 2 ESP8266 will be connected using WiFi, one will control the others LED.
I started by designing the circuit diagram.
I made 2 identical board to communicate between, one will control the LEDs os the other using push buttons.
I exported PNG images from the PCB I designed a converted them to RML files to use in monoFab machine.
After designing the board I printed it with SRM-20 machine and soldered all the components in their place.
Now the next step is to program both boards to communicate among them.
I programed ESP-03 using Arduino IDE:
Transimitter program:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
const char* APIkey = "P3C4GHF6CNT08T2I"; // API key from thingspeak.com
const char* host = "api.thingspeak.com"; // link of the server.
const char* ssid = "FabLab_2.4";
const char* pass = "innovate";
int btn_A = 16;
int btn_B = 17;
void setup() {
Serial.begin(115200);
WiFiClient client;
pinMode(btn_A, INPUT);
pinMode(btn_B, INPUT);
WiFi.begin(ssid, pass);
Serial.println("connecting to WiFi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println();
}
void loop() {
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)){
return;
}
String updateURL = "/update?api_key=";
updateURL += APIkey;
updateURL += "&field1=";
if (digitalRead(btn_A) == HIGH){
updateURL += "10\r\n";
sendURL(updateURL);
}
if (digitalRead(btn_B) == HIGH){
updateURL += "01\r\n";
sendURL(updateURL);
}
if ((digitalRead(btn_A) == HIGH) && (digitalRead(btn_B) == HIGH)){
updateURL += "11\r\n";
sendURL(updateURL);
}
}
void sendURL(String url){
WiFiClient client;
client.print(String("GET ") + url + "HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(1000);
}
Receiver program:
nclude <ESP8266WiFi.h>
#include <WiFiClient.h>
const char* APIkey = "P3C4GHF6CNT08T2I"; // API key from thingspeak.com
const char* host = "api.thingspeak.com"; // link of the server.
const char* ssid = "FabLab_2.4";
const char* pass = "innovate";
int led_A = 5;
int led_B = 6;
int led_C = 7;
int led_D = 13;
void setup() {
Serial.begin(115200);
WiFiClient client;
pinMode(led_A, OUTPUT);
pinMode(led_B, OUTPUT);
pinMode(led_C, OUTPUT);
pinMode(led_D, OUTPUT);
WiFi.begin(ssid, pass);
Serial.println("connecting to WiFi");
while (WiFi.status() != WL_CONNECTED){
Serial.print(".");
delay(500);
}
Serial.println();
}
void loop() {
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)){
return;
}
String getURL = "GET /channels/641607/fields/1.json?api_key=";
getURL += APIkey; // with only the API you will get all result.
String toHost = "Host: ";
toHost += host;
client.println(getURL);
client.println(toHost);
client.println("Connection: close");
client.println();
unsigned long lastRead = millis();
while (millis() - lastRead < 2000){
while (client.available()){
Serial.print(client.read());
lastRead = millis();
}
}
client.stop();
}
Files used can be downloaded Here