Facebook
From Unique Matamata, 1 Year ago, written in Plain Text.
This paste is a reply to http://tinyurl.com/npvbg9u from http://tinyurl.com/npvbg9u - view diff
Embed
Download Paste or View Raw
Hits: 140
  1. WEEK 6
  2.  
  3.  
  4.  
  5. #include <ESP8266WiFi.h>
  6. #include "secrets.h"
  7. #include "ThingSpeak.h"
  8.  
  9. char ssid[] = SECRET_SSID;  
  10. char pass[] = SECRET_PASS;  
  11. int keyIndex = 0;            
  12. WiFiClient  client;
  13.  
  14. unsigned long myChannelNumber = 2103672;
  15. const char * myWriteAPIKey = "PXVDZESPCBS41FV6";
  16.  
  17. int number = 0;
  18. const int irPin = D5;
  19.  
  20. void setup() {
  21.   Serial.begin(115200);
  22.   while (!Serial) {
  23.     ;
  24.   }
  25.  
  26.   WiFi.mode(WIFI_STA);
  27.   ThingSpeak.begin(client);  
  28. }
  29.  
  30. void loop() {
  31.  
  32.  
  33.   if(WiFi.status() != WL_CONNECTED){
  34.     Serial.print("Attempting to connect to SSID: ");
  35.     Serial.println(SECRET_SSID);
  36.     while(WiFi.status() != WL_CONNECTED){
  37.       WiFi.begin(ssid, pass);  
  38.       Serial.print(".");
  39.       delay(5000);    
  40.     }
  41.     Serial.println("\nConnected.");
  42.   }
  43.  
  44.  
  45.   int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
  46.   if(x == 200){
  47.     Serial.println("Channel update successful.");
  48.   }
  49.   else{
  50.     Serial.println("Problem updating channel. HTTP error code " + String(x));
  51.   }
  52.  
  53.  
  54.   number++;
  55.   if(number > 99){
  56.     number = 0;
  57.   }
  58.  
  59.   delay(20000);
  60.  
  61.  
  62.  
  63. WEEK 7
  64.  
  65.  
  66.  
  67. #include <ESP8266WiFi.h>
  68. #include "secrets.h"
  69. #include "ThingSpeak.h"
  70. #include "DHT.h"
  71. #define DHTTYPE DHT11
  72. #define DHTPIN_D3
  73. DHT dht(D3, DHT11);
  74.  
  75. char ssid[] = SECRET_SSID;  
  76. char pass[] = SECRET_PASS;  
  77. int keyIndex = 0;            
  78. WiFiClient  client;
  79.  
  80. unsigned long myChannelNumber = SECRET_CH_ID;
  81. const char * myWriteAPIKey = SECRET_WRITE_APIKEY;
  82.  
  83.  
  84. int number1 = 0;
  85. int number2 = random(0,100);
  86. int number3 = random(0,100);
  87. int number4 = random(0,100);
  88. String myStatus = "";
  89.  
  90. void setup() {
  91.   Serial.begin(115200);  
  92.   while (!Serial) {
  93.     ;
  94.   }
  95.  
  96.   WiFi.mode(WIFI_STA);
  97.   ThingSpeak.begin(client);
  98. }
  99.  
  100. void loop() {
  101.  
  102.   if(WiFi.status() != WL_CONNECTED){
  103.     Serial.print("Attempting to connect to SSID: ");
  104.     Serial.println(SECRET_SSID);
  105.     while(WiFi.status() != WL_CONNECTED){
  106.       WiFi.begin(ssid, pass);
  107.       Serial.print(".");
  108.       delay(5000);    
  109.     }
  110.     Serial.println("\nConnected.");
  111.   }
  112.  
  113.  
  114.   ThingSpeak.setField(1, number1);
  115.   ThingSpeak.setField(2, number2);
  116.   ThingSpeak.setField(3, number3);
  117.   ThingSpeak.setField(4, number4);
  118.  
  119.   if(number1 > number2){
  120.     myStatus = String("field1 is greater than field2");
  121.   }
  122.   else if(number1 < number2){
  123.     myStatus = String("field1 is less than field2");
  124.   }
  125.   else{
  126.     myStatus = String("field1 equals field2");
  127.   }
  128.  
  129.   ThingSpeak.setStatus(myStatus);
  130.  
  131.   int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
  132.   if(x == 200){
  133.     Serial.println("Channel update successful.");
  134.   }
  135.   else{
  136.     Serial.println("Problem updating channel. HTTP error code " + String(x));
  137.   }
  138.  
  139.   number1++;
  140.   if(number1 > 99){
  141.     number1 = 0;
  142.   }
  143.   number2 = random(0,100);
  144.   number3 = random(0,100);
  145.   number4 = random(0,100);
  146.  
  147.   delay(5000);
  148. }
  149.  
  150. WEEK 8
  151.  
  152.  
  153.  
  154. #include "ThingSpeak.h"
  155. #include <ESP8266WiFi.h>
  156. const char ssid[] = "Rinku";
  157. const char pass[] = "sai12345";
  158. int statusCode = 0;
  159. WiFiClient client;
  160.  
  161. unsigned long counterChannelNumber = 2103684;
  162. const char * myCounterReadAPIKey = "76IKZGQ5ZJJWZCM2";
  163. const int FieldNumber1 = 1;
  164. const int FieldNumber2 = 2;
  165.  
  166. void setup()
  167. {
  168. Serial.begin(115200);
  169. WiFi.mode(WIFI_STA);
  170. ThingSpeak.begin(client);
  171. }
  172. void loop()
  173. {
  174. if (WiFi.status() != WL_CONNECTED)
  175. {
  176. Serial.print("Connecting to ");
  177. Serial.print(ssid);
  178. Serial.println("....");
  179. while (WiFi.status() != WL_CONNECTED)
  180. {
  181. WiFi.begin(ssid, pass);
  182. delay(5000);
  183. }
  184. Serial.println("Connected to Wi-Fi Succesfully.");
  185. }
  186.  
  187. long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
  188. statusCode = ThingSpeak.getLastReadStatus();
  189. if (statusCode == 200)
  190. {
  191. Serial.print("Temperature: ");
  192. Serial.println(temp);
  193. }
  194. else
  195. {
  196. Serial.println("Unable to read channel / No internet connection");
  197. }
  198. delay(100);
  199.  
  200. long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
  201. statusCode = ThingSpeak.getLastReadStatus();
  202. if (statusCode == 200)
  203. {
  204. Serial.print("Humidity:");
  205. Serial.println(humidity);
  206. }
  207. else
  208. {
  209. Serial.println("Unable to read channel / No internet connection");
  210. }
  211. delay(100);
  212.  
  213. }
  214.  
  215.  
  216. WEEK 9
  217.  
  218.  
  219.  
  220. #include "ESP8266WiFi.h"
  221. #include "DHT.h"
  222. #define DHTTYPE DHT11
  223. const char* ssid ="Redmi Note 11 Pro+ 5G";
  224. const char* password = "mani@123";
  225. WiFiServer wifiServer(9000);
  226. DHT dht(D4, DHT11);
  227. void setup() {
  228. Serial.begin(115200);
  229. delay(1000);
  230. WiFi.begin(ssid, password);
  231. while (WiFi.status() != WL_CONNECTED) {
  232. delay(1000);
  233. Serial.println("Connecting..");
  234. }
  235. Serial.print("Connected to WiFi. IP:");
  236. Serial.println(WiFi.localIP());
  237. wifiServer.begin();
  238. dht.begin();
  239.  
  240. }
  241.  
  242. void loop() {
  243. WiFiClient client = wifiServer.available();
  244. if (client) {
  245. while (client.connected()) {
  246. while (client.available()&gt;0) {
  247. int h = dht.readHumidity();
  248. client.print("humidity :");
  249. client.println(h);
  250. //Serial.println(sensor_value);
  251. delay(2000);
  252. }
  253. }
  254. client.stop();
  255. Serial.println("Client disconnected");
  256. }
  257. }
  258.  
  259.  
  260.  
  261.  
  262. week 10
  263.  
  264.  
  265. #include <ESP8266WiFi.h>
  266. #include <WiFiUdp.h>
  267. #include "DHT.h"
  268. #define DHTTYPE DHT11
  269. #define WIFI_SSID "lab"
  270. #define WIFI_PASS "12345678"
  271. #define UDP_PORT 4210
  272. DHT dht(D5, DHT11);
  273.  
  274. WiFiUDP UDP;
  275. char packet[255];
  276. char reply[] = "Packet received!";
  277.  
  278. void setup() {
  279.   Serial.begin(115200);
  280.   Serial.println();
  281.   Serial.println(F("DHTxx test!"));
  282.   dht.begin();
  283.  
  284.   WiFi.begin(WIFI_SSID, WIFI_PASS);
  285.  
  286.   Serial.print("Connecting to ");
  287.   Serial.print(WIFI_SSID);
  288.  
  289.   while(WiFi.status()!=WL_CONNECTED)
  290.   {
  291.     delay(2000);
  292.     Serial.print(".");
  293.   }
  294.  
  295.  
  296.   Serial.println();
  297.   Serial.print("Connected! IP address: ");
  298.   Serial.println(WiFi.localIP());
  299.  
  300.  
  301.   UDP.begin(UDP_PORT);
  302.   Serial.print("Listening on UDP port ");
  303.   Serial.println(UDP_PORT);
  304. }
  305.  
  306. void loop() {
  307.   int h = dht.readHumidity();
  308.   int t = dht.readTemperature();
  309.   delay(2000);
  310.   UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
  311.   UDP.write(reply);
  312.   UDP.endPacket();
  313.   UDP.println(t);
  314.   UDP.println(h);
  315.   Serial.println(F("Humidity:\n "));
  316.   Serial.println(h);
  317.  
  318. }