- WEEK 6
- #include <ESP8266WiFi.h>
- #include "secrets.h"
- #include "ThingSpeak.h"
- char ssid[] = SECRET_SSID;
- char pass[] = SECRET_PASS;
- int keyIndex = 0;
- WiFiClient client;
- unsigned long myChannelNumber = 2103672;
- const char * myWriteAPIKey = "PXVDZESPCBS41FV6";
- int number = 0;
- const int irPin = D5;
- void setup() {
- Serial.begin(115200);
- while (!Serial) {
- ;
- }
- WiFi.mode(WIFI_STA);
- ThingSpeak.begin(client);
- }
- void loop() {
- if(WiFi.status() != WL_CONNECTED){
- Serial.print("Attempting to connect to SSID: ");
- Serial.println(SECRET_SSID);
- while(WiFi.status() != WL_CONNECTED){
- WiFi.begin(ssid, pass);
- Serial.print(".");
- delay(5000);
- }
- Serial.println("\nConnected.");
- }
- int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
- if(x == 200){
- Serial.println("Channel update successful.");
- }
- else{
- Serial.println("Problem updating channel. HTTP error code " + String(x));
- }
- number++;
- if(number > 99){
- number = 0;
- }
- delay(20000);
- WEEK 7
- #include <ESP8266WiFi.h>
- #include "secrets.h"
- #include "ThingSpeak.h"
- #include "DHT.h"
- #define DHTTYPE DHT11
- #define DHTPIN_D3
- DHT dht(D3, DHT11);
- char ssid[] = SECRET_SSID;
- char pass[] = SECRET_PASS;
- int keyIndex = 0;
- WiFiClient client;
- unsigned long myChannelNumber = SECRET_CH_ID;
- const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
- int number1 = 0;
- int number2 = random(0,100);
- int number3 = random(0,100);
- int number4 = random(0,100);
- String myStatus = "";
- void setup() {
- Serial.begin(115200);
- while (!Serial) {
- ;
- }
- WiFi.mode(WIFI_STA);
- ThingSpeak.begin(client);
- }
- void loop() {
- if(WiFi.status() != WL_CONNECTED){
- Serial.print("Attempting to connect to SSID: ");
- Serial.println(SECRET_SSID);
- while(WiFi.status() != WL_CONNECTED){
- WiFi.begin(ssid, pass);
- Serial.print(".");
- delay(5000);
- }
- Serial.println("\nConnected.");
- }
- ThingSpeak.setField(1, number1);
- ThingSpeak.setField(2, number2);
- ThingSpeak.setField(3, number3);
- ThingSpeak.setField(4, number4);
- if(number1 > number2){
- myStatus = String("field1 is greater than field2");
- }
- else if(number1 < number2){
- myStatus = String("field1 is less than field2");
- }
- else{
- myStatus = String("field1 equals field2");
- }
- ThingSpeak.setStatus(myStatus);
- int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
- if(x == 200){
- Serial.println("Channel update successful.");
- }
- else{
- Serial.println("Problem updating channel. HTTP error code " + String(x));
- }
- number1++;
- if(number1 > 99){
- number1 = 0;
- }
- number2 = random(0,100);
- number3 = random(0,100);
- number4 = random(0,100);
- delay(5000);
- }
- WEEK 8
- #include "ThingSpeak.h"
- #include <ESP8266WiFi.h>
- const char ssid[] = "Rinku";
- const char pass[] = "sai12345";
- int statusCode = 0;
- WiFiClient client;
- unsigned long counterChannelNumber = 2103684;
- const char * myCounterReadAPIKey = "76IKZGQ5ZJJWZCM2";
- const int FieldNumber1 = 1;
- const int FieldNumber2 = 2;
- void setup()
- {
- Serial.begin(115200);
- WiFi.mode(WIFI_STA);
- ThingSpeak.begin(client);
- }
- void loop()
- {
- if (WiFi.status() != WL_CONNECTED)
- {
- Serial.print("Connecting to ");
- Serial.print(ssid);
- Serial.println("....");
- while (WiFi.status() != WL_CONNECTED)
- {
- WiFi.begin(ssid, pass);
- delay(5000);
- }
- Serial.println("Connected to Wi-Fi Succesfully.");
- }
- long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
- statusCode = ThingSpeak.getLastReadStatus();
- if (statusCode == 200)
- {
- Serial.print("Temperature: ");
- Serial.println(temp);
- }
- else
- {
- Serial.println("Unable to read channel / No internet connection");
- }
- delay(100);
- long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
- statusCode = ThingSpeak.getLastReadStatus();
- if (statusCode == 200)
- {
- Serial.print("Humidity:");
- Serial.println(humidity);
- }
- else
- {
- Serial.println("Unable to read channel / No internet connection");
- }
- delay(100);
- }
- WEEK 9
- #include "ESP8266WiFi.h"
- #include "DHT.h"
- #define DHTTYPE DHT11
- const char* ssid ="Redmi Note 11 Pro+ 5G";
- const char* password = "mani@123";
- WiFiServer wifiServer(9000);
- DHT dht(D4, DHT11);
- void setup() {
- Serial.begin(115200);
- delay(1000);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(1000);
- Serial.println("Connecting..");
- }
- Serial.print("Connected to WiFi. IP:");
- Serial.println(WiFi.localIP());
- wifiServer.begin();
- dht.begin();
- }
- void loop() {
- WiFiClient client = wifiServer.available();
- if (client) {
- while (client.connected()) {
- while (client.available()>0) {
- int h = dht.readHumidity();
- client.print("humidity :");
- client.println(h);
- //Serial.println(sensor_value);
- delay(2000);
- }
- }
- client.stop();
- Serial.println("Client disconnected");
- }
- }
- week 10
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- #include "DHT.h"
- #define DHTTYPE DHT11
- #define WIFI_SSID "lab"
- #define WIFI_PASS "12345678"
- #define UDP_PORT 4210
- DHT dht(D5, DHT11);
- WiFiUDP UDP;
- char packet[255];
- char reply[] = "Packet received!";
- void setup() {
- Serial.begin(115200);
- Serial.println();
- Serial.println(F("DHTxx test!"));
- dht.begin();
- WiFi.begin(WIFI_SSID, WIFI_PASS);
- Serial.print("Connecting to ");
- Serial.print(WIFI_SSID);
- while(WiFi.status()!=WL_CONNECTED)
- {
- delay(2000);
- Serial.print(".");
- }
- Serial.println();
- Serial.print("Connected! IP address: ");
- Serial.println(WiFi.localIP());
- UDP.begin(UDP_PORT);
- Serial.print("Listening on UDP port ");
- Serial.println(UDP_PORT);
- }
- void loop() {
- int h = dht.readHumidity();
- int t = dht.readTemperature();
- delay(2000);
- UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
- UDP.write(reply);
- UDP.endPacket();
- UDP.println(t);
- UDP.println(h);
- Serial.println(F("Humidity:\n "));
- Serial.println(h);
- }