Guest User

Untitled

a guest
Nov 24th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <Adafruit_Sensor.h> //Bibliotecas usadas no código
  2. #include <ArduinoJson.h>
  3. #include <ESP8266WiFi.h>
  4. #include <PubSubClient.h>
  5.  
  6. #include "stdlib.h"
  7.  
  8. #define PIR 7 // pino do sensor de presença
  9. #define PIRTYPE PIR
  10. PIR pir(D7, 3.3);
  11.  
  12. // Update these with values suitable for your network.
  13.  
  14. const char* ssid = "2.4G_COTONETES";
  15. const char* password = "31012015anapaulalucas";
  16. const char* mqttServer = "iot.eclipse.org";
  17. const int mqttPort = 1883;
  18. const char* mqttUser = "";
  19. const char* mqttPassword = "";
  20.  
  21. char json[100];
  22.  
  23. WiFiClient espClient;
  24. PubSubClient client(espClient);
  25.  
  26. void setup()
  27. {
  28. Serial.begin(115200);
  29. Serial.println("Sensor PIR test!");
  30. pir.begin();
  31.  
  32. WiFi.begin(ssid, password);
  33.  
  34. while (WiFi.status() != WL_CONNECTED) {
  35. delay(500);
  36. Serial.println("Connecting to WiFi..");
  37. }
  38.  
  39. Serial.println("Connected to the WiFi network");
  40. client.setServer(mqttServer, mqttPort);
  41.  
  42. while (!client.connected()) {
  43. Serial.println("Connecting to MQTT...");
  44.  
  45. if (client.connect("ESP8266Client", mqttUser, mqttPassword)) {
  46. Serial.println("connected");
  47. } else {
  48. Serial.print("failed with state ");
  49. Serial.print(client.state());
  50. delay(2000);
  51. }
  52. }
  53. }
Add Comment
Please, Sign In to add comment