Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions Nodemcu-Web-Telegram-relay-controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int outputQuantity = 10; //should not exceed 10
boolean outputInverted = true; //true or false

// Write the text description of the output channel
String buttonText[10] = {"22. Settore 1", "24. Settore 2", "26. Settore 3", "28. Settore 4", "30. Luci esterne", "32. na", "34. na", "36. na", "38. na", "40. na"};
String buttonText[10] = {"22. Settore 1", "24. Settore 2", "26. Settore 3", "28. Settore 4", "30. Settore 5", "32. Luci Esterne", "34. na", "36. na", "38. na", "40. na"};
int outp = 0;
boolean printLastCommandOnce = false;
boolean printButtonMenuOnce = false;
Expand All @@ -55,17 +55,20 @@ float tempOutDeg = 0.0;
float umid_aria = 0.0;


const char* ssid = "ssid";
const char* password = "password";
const char* ssid = "xxx";
const char* password = "xxx";


// Initialize Telegram BOT

#define BOTtoken "aaaaaa:bbbbbbb" //"aaaa:bbbbb" //token of FlashledBOT
#define BOTname "BOTname" //""
#define BOTusername "BOTusername"//""
#define BOTtoken "xx:xxx" //"425354869:AAFc9Z6HVVm3EJHonQoEqscSNLwMBQTSvyY" //token of FlashledBOT
#define BOTname "xxx" //"AdreaniSpruzziniController"
#define BOTusername "xx"//"AdreaniSpruzziniControllerBot"

const String id_proprietario = "xx";

String id_scrittore_messaggio = "xx";

String id_proprietario = "0123456789";

TelegramBOT bot(BOTtoken, BOTname, BOTusername);

Expand All @@ -74,12 +77,13 @@ long Bot_lasttime; //last time messages' scan has been done
bool Start = false;

String message_read;
String wellcome = "Bentornato";
String wellcome = "Bentornato Fede";
String help_msg = "Comandi: /start per avviare il sistema /Hn per accendere il pin n /Ln per spegnere il led n /cicloXX per avviare un ciclo intero di XX minuti (per stazione) /stato per sapere lo stato generale dei pin /Hall per accendere tutto e /Lall per spegnere tutto";

String ip_esterno;



bool web = false;
bool isCiclo = false;

Expand All @@ -89,7 +93,17 @@ bool isCiclo = false;
void Bot_ExecMessages() {
for (int i = 1; i < bot.message[0][0].toInt() + 1; i++) {
message_read = bot.message[i][5].substring(1, bot.message[i][5].length());
id_proprietario = bot.message[i][4];

id_scrittore_messaggio = bot.message[i][4];


if (id_proprietario != id_scrittore_messaggio) {

bot.sendMessage(id_proprietario, "!!! ATTENZIONE FEDERICO !!!", "");
bot.sendMessage(id_proprietario, "Accesso sospetto da parte di una persona sconosciuta", "");
bot.sendMessage(id_proprietario, id_scrittore_messaggio, "");

}

WiFiClient client = server.available();

Expand Down Expand Up @@ -238,7 +252,7 @@ void setup() {

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress arduino_ip ( 192, 168, 1, 177);
IPAddress arduino_ip ( 192, 168, 1, 170);
IPAddress gateway_ip ( 192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);

Expand Down Expand Up @@ -708,10 +722,10 @@ void printHtmlFooter(WiFiClient client) {
allOff = "";

//printing last part of the html
client.println("\n<h3 align=\"center\">&copy; Author - Adreani Federico <br> " + ip_esterno + " - 09-09-2017 - ");
client.println("\n<h3 align=\"center\">&copy; Author - Adreani Federico <br> " + ip_esterno + " - 01/06/2018 - ");
client.println(rev);
client.println("</h3></div>\n</div>\n</body>\n</html>");
//client.println("<iframe src='http://www.pattoonline.com/arduino/arduino.php'></iframe>");
//client.println("<iframe src='http://www.xxxxxx.com/arduino/arduino.php'></iframe>");

delay(1); // give the web browser time to receive the data

Expand Down Expand Up @@ -968,13 +982,12 @@ void checkForClient() {
//
void cicloSpruzzini(WiFiClient client, int durata) {

bot.message[0][0] = "";

writer("inizio ciclo spruzzini --> " + String(durata));



for ( unsigned int a = 0; a < 4; a++ )
for ( unsigned int a = 0; a < 5; a++ )
{
writer("Inizio settore " + String(a));

Expand All @@ -1000,6 +1013,8 @@ void cicloSpruzzini(WiFiClient client, int durata) {
void aspetta(int durata) {
for (int i = 0; i < 600; i++) {
for (int b = 0; b < durata; b++) {


delay(100);
}
}
Expand All @@ -1015,7 +1030,7 @@ void writer(String stringa) {
Serial.println(stringa);


bot.sendMessage(id_proprietario, stringa, "");
bot.sendMessage(id_scrittore_messaggio, stringa, "");

Serial.println("nessuna chat su telegram");

Expand All @@ -1025,8 +1040,9 @@ void writer(String stringa) {

void get_ip_esterno() {
HTTPClient http;
http.begin("http://ipServer");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
http.begin("http://www.xxxx.com/arduino/arduino.php");
// http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// http.POST("title=foo&body=bar&userId=1");
ip_esterno = http.getString();
http.end();
}