-------- 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();
}
}
----------------