• Система автоматизации с открытым исходным кодом на базе esp8266/esp32 микроконтроллеров и приложения IoT Manager. Наша группа в Telegram

Нужна помощь ESP 8266 Отправка уведомлений

deltacanon

New member
Я только открыл для себя мир микроконтроллеров. Можно ли сделать газ-сенсор, датчик протечки воды с возможностью отправки уведомлений по одному из способов: смс, e-mail, whatsapp, telegram, push. Если можно помогите со скетчем.
 

deltacanon

New member
собрал по такой схеме газ-сенсор, со скетчем проблемы еще даже ничего не делал.
 

Вложения

deltacanon

New member
нашел скетч, для отправки показаний на сервер easylot но он меня не устраивает.
Код:
 /*
  Created by Igor Jarc
See http://iot-playground.com for details
Please use community forum on website do not contact author directly
External libraries:
- https://github.com/adamvr/arduino-base64
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
#include <ESP8266WiFi.h>
#include <Base64.h>

//AP definitions
#define AP_SSID "your AP SSID"
#define AP_PASSWORD "your AP password"

// EasyIoT server definitions
#define EIOT_USERNAME    "admin"
#define EIOT_PASSWORD    "test"
#define EIOT_IP_ADDRESS  "192.168.1.5"
#define EIOT_PORT        80
#define EIOT_NODE        "N8S0"

#define INPUT_PIN         2
#define USER_PWD_LEN      40


char unameenc[USER_PWD_LEN];
bool oldInputState;


void setup() {
  Serial.begin(115200);
  pinMode(INPUT_PIN, INPUT);
 
  wifiConnect();
   
  char uname[USER_PWD_LEN];
  String str = String(EIOT_USERNAME)+":"+String(EIOT_PASSWORD); 
  str.toCharArray(uname, USER_PWD_LEN);
  memset(unameenc,0,sizeof(unameenc));
  base64_encode(unameenc, uname, strlen(uname));
 
  oldInputState = !digitalRead(INPUT_PIN);
}

void loop() {
  int inputState = digitalRead(INPUT_PIN);; 
 
  if (inputState != oldInputState)
  {
    sendInputState(inputState);
    oldInputState = inputState;
  }
}

void wifiConnect()
{
    Serial.print("Connecting to AP");
    WiFi.begin(AP_SSID, AP_PASSWORD);
    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected"); 
}

void sendInputState(bool inputState)
{ 
   WiFiClient client;
  
   while(!client.connect(EIOT_IP_ADDRESS, EIOT_PORT)) {
    Serial.println("connection failed");
    wifiConnect();
  }
  String url = "";
  String command = "";
 
  if (inputState)
    command = "ControlOn";
  else
    command = "ControlOff";
 
  url = "/Api/EasyIoT/Control/Module/Virtual/"+ String(EIOT_NODE) + "/"+command; // generate EasIoT server node URL

  Serial.print("POST data to URL: ");
  Serial.println(url);
 
  client.print(String("POST ") + url + " HTTP/1.1\r\n" +
               "Host: " + String(EIOT_IP_ADDRESS) + "\r\n" +
               "Connection: close\r\n" +
               "Authorization: Basic " + unameenc + " \r\n" +
               "Content-Length: 0\r\n" +
               "\r\n");

  delay(100);
    while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
 
  Serial.println();
  Serial.println("Connection closed");
}
 

Сергей_Ф

Moderator
Команда форума
@deltacanon делаю библиотеку для отправки почты. Сейчас точно работает через аккаунт на mail.ru, Yandex и mail.de. Если надо, могу прислать, хотя она еще не отшлифованна. И отпечаток (fingerprint) с сервера для SSL соединения надо получать вручную.
 

rublan

New member
Почему не получается отправить Push?
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
/* user parameters */
const char* ssid = "IoT";
const char* password = "12345678";
// IDS - unique device id from IoT Manager application: Start IoT Manager, goto "Statistic" and press "Send ids to email"
// Also, you can get ids via MQTT after HELLO message.
// ids will be always changed after IoT Manager reinstall on mobile device
String ids = "91433959-a3f5-4cc1-aa28-22a6467b52f3"; // its not real IDS, please change
/* end of user parameters */
const char* host = "onesignal.com";
const int httpsPort = 443;
String url = "/api/v1/notifications";
void push(String msg) {
// Use WiFiClientSecure class to create TLS connection
WiFiClientSecure client;
Serial.print("PUSH: connecting to ");
Serial.println(host);
if (!client.connect(host, httpsPort)) {
Serial.println("connection failed");
return;
}
Serial.println("PUSH: try to send push notification...");
// please, do not change app_id - its IoT Manager id at onesignal.com
// more info at https://documentation.onesignal.com/v3.0/reference#create-notification
String data = "{\"app_id\": \"8871958c-5f52-11e5-8f7a-c36f5770ade9\",\"include_player_ids\":[\"" + ids + "\"],\"android_group\":\"IoT Manager\",\"contents\": {\"en\": \"" + msg + "\"}}";
Serial.print("PUSH: requesting URL: ");
Serial.println(url);
client.println(String("POST ") + url + " HTTP/1.1");
client.print("Host:");
client.println(host);
client.println("User-Agent: esp8266.Arduino.IoTmanager");
client.print("Content-Length: ");
client.println(data.length());
client.println("Content-Type: application/json");
client.println("Connection: close");
client.println();
client.println(data);
Serial.println("PUSH: done. Restart esp8266 for push again.");
}
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Push notification for IoT Manager");
Serial.println();
Serial.print("PUSH: connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("PUSH: WiFi connected");
push("test message");
}
void loop() {
}
Serial monitor выдаёт "Connection failed"
 
Сверху Снизу