Esp8266 Nodmcu v2 Yardım

Katılım
29 Eyl 2018
Mesajlar
8
Puanları
1
Yaş
40
Merhaba arkadaşlar bir proje üstünde çalışıyorum, pır dedektör görünce, cep telefonuna push mesaj atmasını istiyorum, push mesaj için api aldım örneği karta yüklediğimde mesajlar geliyor, birde pır dedektör kodu buldum, onda da sorun yok sorunsuz çalışıyor,, sorun ikisini aynı anda nasıl kullanabilirim? yani sensör algıladığında mesajı nasıl yollatırım? kodları yazıyorum bilen birisi varsa yardımcı olursa çok sevinirim.

Kod:
--------  Esp8266 Nodmcu v2 Pır Dedektör Kodu --------





int Status = 12;

int sensor = 13;



void setup() {

  pinMode(sensor, INPUT); // declare sensor as input

  pinMode(Status, OUTPUT);  // declare LED as output

}



void loop(){

  long state = digitalRead(sensor);

  delay(1000);

    if(state == HIGH){

      digitalWrite (Status, HIGH);

      Serial.println("Motion detected!");

    }

    else {

      digitalWrite (Status, LOW);

      Serial.println("Motion absent!");

      }

}

------------------------- kod bitişi ------------



Buda Pushetta Kodu bunu direk yazdığımda aralıksız mesaj yolluyor telefona--------



#include <ESP8266WiFi.h>

#include <WiFiClient.h>



char APIKEY[] = "4f3352a0d98a59313b322078ffc54ca373f7cadb"; // Put here your API key. It's in the dashboard

char CHANNEL[] = "botecalarm";                               // and here your channel name



char serverName[] = "api.pushetta.com";

boolean lastConnected = false;



int status = WL_IDLE_STATUS;

const char* ssid = "okhan";  //  your network SSID (name)

const char* pass = "atakan2009";   // your network password



IPAddress ipMulti (192, 168, 2, 121);



void setup() {

  WiFiClient client;



  Serial.begin(115200);

 

  // setting up Station AP

  WiFi.begin(ssid, pass);



  // Wait for connect to AP

  Serial.print("[Connecting]");

  Serial.print(ssid);

  int tries = 0;

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

    tries++;

    if (tries > 30) {

      break;

    }

  }

  Serial.println("Connected to wifi");



}



void loop()

{



  Serial.println("Connecting to Pushetta");



  // Use WiFiClient class to create TCP connections

  WiFiClient client;

  const int httpPort = 80;

  if (!client.connect("api.pushetta.com", httpPort)) {

    Serial.println("Connection failed");

    return;

  }



  sendToPushetta(CHANNEL, "Hilal!");

  sendToPushetta(CHANNEL, "YAHYA!");

  delay(60000);

}





//Function for sending the request to Pushetta

void sendToPushetta(char channel[], String text) {

  WiFiClient client;

  client.stop();



  if (client.connect(serverName, 80))

  {

    client.print("POST /api/pushes/");

    client.print(channel);

    client.println("/ HTTP/1.1");

    client.print("Host: ");

    client.println(serverName);

    client.print("Authorization: Token ");

    client.println(APIKEY);

    client.println("Content-Type: application/json");

    client.print("Content-Length: ");

    client.println(text.length() + 46);

    client.println();

    client.print("{ \"body\" : \"");

    client.print(text);

    client.println("\", \"message_type\" : \"text/plain\" }");

    client.println();

  }

}

----------------
Yardımlarınızı bekliyorum
 
Moderatör tarafında düzenlendi:
konunu yeni gördüm hocam söyle bi sey yap..
Calisip calismadigini bilmiyorum ama calismasi lazim

C:
  #include < ESP8266WiFi.h >
  #include < WiFiClient.h >

  char APIKEY[] = "4f3352a0d98a59313b322078ffc54ca373f7cadb"; // Put here your API key. It's in the dashboard

char CHANNEL[] = "botecalarm"; // and here your channel name

char serverName[] = "api.pushetta.com";

boolean lastConnected = false;

int status = WL_IDLE_STATUS;

const char * ssid = "okhan"; // your network SSID (name)

const char * pass = "atakan2009"; // your network password

IPAddress ipMulti(192, 168, 2, 121);

int Status = 12;

int sensor = 13;

void setup() {

  pinMode(sensor, INPUT); // declare sensor as input

  pinMode(Status, OUTPUT); // declare LED as output

  SetupWifi();

}

void loop() {

  long state = digitalRead(sensor);

  delay(1000);

  if (state == HIGH) {

    digitalWrite(Status, HIGH);

    Serial.println("Motion detected!");

    WifiBaglantiBaslat();

  } else {

    digitalWrite(Status, LOW);

    Serial.println("Motion absent!");

  }

}

void SetupWifi()
{

  WiFiClient client;

  Serial.begin(115200);

  // setting up Station AP
  WiFi.begin(ssid, pass);

  // Wait for connect to AP
  Serial.print("[Connecting]");
  Serial.print(ssid);
  int tries = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    tries++;
    if (tries > 30) {
      break;
    }
  }
  Serial.println("Connected to wifi");

}
void WifiBaglantiBaslat()

{

  Serial.println("Connecting to Pushetta");

  // Use WiFiClient class to create TCP connections

  WiFiClient client;

  const int httpPort = 80;

  if (!client.connect("api.pushetta.com", httpPort)) {

    Serial.println("Connection failed");

    return;

  }

  sendToPushetta(CHANNEL, "Hilal!");

  sendToPushetta(CHANNEL, "YAHYA!");

  delay(60000);

}

//Function for sending the request to Pushetta

void sendToPushetta(char channel[], String text) {

  WiFiClient client;

  client.stop();

  if (client.connect(serverName, 80))

  {

    client.print("POST /api/pushes/");

    client.print(channel);

    client.println("/ HTTP/1.1");

    client.print("Host: ");

    client.println(serverName);

    client.print("Authorization: Token ");

    client.println(APIKEY);

    client.println("Content-Type: application/json");

    client.print("Content-Length: ");

    client.println(text.length() + 46);

    client.println();

    client.print("{ \"body\" : \"");

    client.print(text);

    client.println("\", \"message_type\" : \"text/plain\" }");

    client.println();

  }

}
 
Merhaba arkadaşlar, istediğim gibi şekillendirdim, ihtiyacı olan arkadaşlar, kullanabilir. blylnk kutuphanesi ile bu işlemi gerçekleştirdim, ayrıca blylnk uygulamasını cebinize yükleyeceksiniz, api keyi koda gireceksiniz, uygulama içine widget ekleyip notification ekleyeceksiniz. sensörleri bağlayın, algılama olduğu zaman bildirim olarak telefonunuza gelir.

Kullanıdığım geliştirme kartı esp8266 nodemcu v2 arkadaşlar!

C#:
#include <ESP8266WiFi.h>
#define BLYNK_PRINT Serial    //
#include <BlynkSimpleEsp8266.h> // NETTEN HABERLEŞME YAZILIM KUTUPHANESİ
char auth[] = "BLYLNK APİ KEYİNİZİ GİRİN"; // TOKEN KODUM

/* KABLOSUZ AĞ BAĞLANMA KODLARIM */
char ssid[] = "KABLOSU AĞ ADINIZ";
char pass[] = "KABLOSUZ ŞİFRENİZ";
/* YAHYA KILIÇASLAN  ALARM SİSTEMİ*/
/* 01.05.2018*/
/* KULLANILACAK PIN UÇLARIM */
#define pirLedPin D7 // PIR LED YAKMAK İÇİN 7 NOLU DİJİTAL PİNİM
#define suLedPin D8 // SU LED YAKMAK İÇİN 7 NOLU DİJİTAL PİNİM
#define pirPin D2 // HAREKET SENSÖRÜ
#define suPin D3 // SU BASKINI SENSORU
#define gazPin D4 // GAZ DEDEKTÖRÜ
#define dumanPin D5 // DUMAN DEDKTÖRÜ
int pirValue; // PIR DEĞERİ
int suValue; // SU BASKINI DEGERI
int gazValue; // GAZ DEĞERİNİ OKU
int dumanValue; // SU DEĞERİNİ OKU

/* PİN DURUMLARINI BELİRLE GİRİŞ/ÇIKIŞ */
void setup()
{
  Serial.begin(115200);
  delay(1000);
  Blynk.begin(auth, ssid, pass);
  pinMode(pirLedPin, OUTPUT);
  pinMode(suLedPin, OUTPUT);
  pinMode(pirPin, INPUT);
  pinMode(suPin, INPUT);
  pinMode(gazPin, INPUT);
  pinMode(dumanPin, INPUT);
  digitalWrite(suLedPin, LOW);
  digitalWrite(pirLedPin, LOW);
}
/* PİN DURUMLARINI BELİRLE GİRİŞ/ÇIKIŞ  KODLARIN BİTİŞİ */
/****************************************************** */
/* OKUNAN DEĞERLERİ MESAJ İLE YOLLA LED YAK VS */
void loop()
{
  getValues();
  Blynk.run();
}
void getValues(void)
{
  pirValue = digitalRead(pirPin);
  suValue = digitalRead(suPin);
  gazValue = digitalRead(gazPin);
  dumanValue = digitalRead(dumanPin);
  if (pirValue)
  {
    
    Serial.println("HAREKET ALGILANDI");
    Blynk.notify("EVDE HIRSIZ VAR!"); 
  }
  if (suValue)
  {
    
    Serial.println("ZEMINDE SU ALGILANDI");
    Blynk.notify("EVDE SU BASKINI VAR!"); 
  }
   if (gazValue)
  {
    
    Serial.println("GAZ SIZINTISI");
    Blynk.notify("DOĞALGAZ SIZINTISI VAR!"); 
  }
   if (dumanValue)
  {
    
    Serial.println("DUMAN ALGILANDI");
    Blynk.notify("YANGIN VAR!"); 
  }
  digitalWrite(pirLedPin, pirValue);
  digitalWrite(suLedPin, suValue);
   digitalWrite(pirLedPin, gazValue);
    digitalWrite(pirLedPin, dumanValue);
 
}

Arkadaşlar, wifimanager denen bir şey var, bunu da bu kod içine entegre etmekte bana yardımcı olabilirmisiniz? wifimanager ile, istediğim kablosuz ağa bağlanıp sistemi istediğimiz ağda çalıştırmak için, kodu aşağıga paylaşıyorum


C#:
#include <ESP8266WiFi.h>    //https://github.com/esp8266/Arduino
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>     //https://github.com/tzapu/WiFiManager
// set pin numbers:
#define D0 16             // USER LED Wake
#define wifipin  D0        // the number of the LED pin
#define D1 5
#define ConfigWiFi_Pin D1
#define ESP_AP_NAME "BotechAlarm"
void setup()
{
  // initialize pin D0 as an output.
  pinMode(wifipin, OUTPUT);
  pinMode(ConfigWiFi_Pin,INPUT_PULLUP);

  Serial.begin(115200);
  digitalWrite(wifipin,LOW);//Turn on the LED
  //WiFiManager
  //Local intialization. Once its business is done, there is no need to keep it around
  WiFiManager wifiManager;
  if(digitalRead(ConfigWiFi_Pin) == LOW) // Press button
  {
    //reset saved settings
    wifiManager.resetSettings(); // go to ip 192.168.4.1 to config
  }
  //fetches ssid and password from EEPROM and tries to connect
  //if it does not connect, it starts an access point with the specified name
  //and goes into a blocking loop awaiting configuration
  wifiManager.autoConnect(ESP_AP_NAME);
  while (WiFi.status() != WL_CONNECTED)
  {
     delay(250);
     Serial.print(".");
  }
  Serial.println("WiFi connected"); 
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  digitalWrite(wifipin,HIGH);
}
void loop()
{
 digitalWrite(D0, HIGH);  // turn off the LED 
 delay(2000);             // wait for two seconds
 digitalWrite(D0, LOW);   // turn on the LED
 delay(2000);             // wait for two seconds
}
 
D1 pinine bir buton bağlıyorsunuz (butonun diğer ucu gnd ye bağlı), cihaza bu butona basılı tutarken güç veriyorsunuz. Cihaz configürasyon modunda açılıyor. Kendi wifi alanını oluşturuyor yani(wifi adı sizde
BotechAlarm). Bir cep telefonunun hücresel verisini kapatıp wifi ile bu ağa bağlanıyorsunuz. internet tarayıcı ile 192.168.4.1 adresine gidip cihazın bağlanacağı wifi adı ve şifresini yazıp kaydet deyince cihaz ayarları kaydedip restart yapması lazım. ayrladığınız wifi üzerinden internet bağlantısı sağlanmış oluyor. sonra cep telefonundaki Blynk uygulaması üzerinden cihaza ulaşabilirsiniz.
 

Forum istatistikleri

Konular
127,952
Mesajlar
913,882
Kullanıcılar
449,600
Son üye
psychedelic

Yeni konular

Geri
Üst