ESP8266 DOOR SENSOR

9 years 8 months ago #650 by mamg15
ESP8266 DOOR SENSOR was created by mamg15
Hi, thanks for this amazing software and hard work of this.

I start recently make some test with the low powered sensor, but for now i try to make it with a esp8266 and the iot server for windows.

Can someone upload and example of code, because i dont get to work right, all i get its random state.

/*
V1.0 - first version
V1.1 - adopt to new library

Created by Igor Jarc <This email address is being protected from spambots. You need JavaScript enabled to view it.>
See iot-playground.com for details

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 <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>

Esp8266EasyIoT esp;

SoftwareSerial serialEsp(10, 11);



#define RELAY_1 13 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
#define CHILD_ID_DOOR 3
#define DOOR_PIN 22
#define INTERRUPT_SENSOR 52
Esp8266EasyIoTMsg msgDoor(CHILD_ID_DOOR, V_DOOR);
int lastDoorValue = -1;
void setup()
{
serialEsp.begin(9600);
Serial.begin(115200);

Serial.println("EasyIoTEsp init");

esp.begin(incomingMessage, 3, &serialEsp, &Serial);
//esp.begin(incomingMessage, 3, &serialEsp);

pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_1 + 1, OUTPUT);
pinMode(DOOR_PIN, INPUT);



esp.present(1, S_DIGITAL_OUTPUT);
esp.present(2, S_DIGITAL_OUTPUT);
esp.present(CHILD_ID_DOOR, S_DOOR);
}

void loop()
{
esp.process();
}

void incomingMessage(const Esp8266EasyIoTMsg &message) {
// We only expect one type of message from controller. But we better check anyway.
int doorValue = digitalRead(DOOR_PIN);
if (doorValue != lastDoorValue) {
Serial.println(doorValue);
esp.send(msgDoor.set(doorValue==0?0:1));
lastDoorValue = doorValue;}
Serial.println("New message");
if (message.type==V_DIGITAL_VALUE) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);

Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}



Attachments:

Please Log in or Create an account to join the conversation.

9 years 8 months ago #651 by tonyn79
Replied by tonyn79 on topic ESP8266 DOOR SENSOR
I am not 100% on the code but try to set your serial rate from 115200 to 9600 on serial. I was locking up on me with the high baud rate.

Please Log in or Create an account to join the conversation.

9 years 8 months ago #653 by mamg15
Replied by mamg15 on topic ESP8266 DOOR SENSOR
when im using arduino mini i have the locking up problem, i resolved lowering the serial to 9600, but for this skecht im using mega, the relay works, but the door sensor on server randomly change, not matter what state is the pin or button.

Please Log in or Create an account to join the conversation.

9 years 8 months ago #654 by tonyn79
Replied by tonyn79 on topic ESP8266 DOOR SENSOR
I am working on that issue myself today. I have a program that I built using a mega, I want to transfer to a mini but I am running into issues, I am not sure where the problem is but I will post my findings if I can get it to work. I found this issue after trying to upload program to mini and would not connect to server, then I loaded one of the examples and it connected right up , so I know the hardware is setup correctly. Just need to find the bug.

Please Log in or Create an account to join the conversation.

9 years 8 months ago #675 by mamg15
Replied by mamg15 on topic ESP8266 DOOR SENSOR
I just test with some changes in the code, or with the input arduino , but no changes.

I suspect that my error is sending the correct instruction on the skecht to the esp library, becuase no matter what state the pin is the server show random changes on the door sensor, so maybe if i beg for one example of how the esplibrary wait for the correct instrution for send the comand to server.

Please Log in or Create an account to join the conversation.

9 years 8 months ago #683 by EasyIoT
Replied by EasyIoT on topic ESP8266 DOOR SENSOR

mamg15 wrote: Hi, thanks for this amazing software and hard work of this.

I start recently make some test with the low powered sensor, but for now i try to make it with a esp8266 and the iot server for windows.

Can someone upload and example of code, because i dont get to work right, all i get its random state.

/*
V1.0 - first version
V1.1 - adopt to new library

Created by Igor Jarc <This email address is being protected from spambots. You need JavaScript enabled to view it.>
See iot-playground.com for details

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 <Esp8266EasyIoT.h>
#include <SoftwareSerial.h>

Esp8266EasyIoT esp;

SoftwareSerial serialEsp(10, 11);



#define RELAY_1 13 // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
#define CHILD_ID_DOOR 3
#define DOOR_PIN 22
#define INTERRUPT_SENSOR 52
Esp8266EasyIoTMsg msgDoor(CHILD_ID_DOOR, V_DOOR);
int lastDoorValue = -1;
void setup()
{
serialEsp.begin(9600);
Serial.begin(115200);

Serial.println("EasyIoTEsp init");

esp.begin(incomingMessage, 3, &serialEsp, &Serial);
//esp.begin(incomingMessage, 3, &serialEsp);

pinMode(RELAY_1, OUTPUT);
pinMode(RELAY_1 + 1, OUTPUT);
pinMode(DOOR_PIN, INPUT);



esp.present(1, S_DIGITAL_OUTPUT);
esp.present(2, S_DIGITAL_OUTPUT);
esp.present(CHILD_ID_DOOR, S_DOOR);
}

void loop()
{
esp.process();
}

void incomingMessage(const Esp8266EasyIoTMsg &message) {
// We only expect one type of message from controller. But we better check anyway.
int doorValue = digitalRead(DOOR_PIN);
if (doorValue != lastDoorValue) {
Serial.println(doorValue);
esp.send(msgDoor.set(doorValue==0?0:1));
lastDoorValue = doorValue;}
Serial.println("New message");
if (message.type==V_DIGITAL_VALUE) {
// Change relay state
digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);

Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}




Function incomingMessage is executed when you receive message from EasyIoT server, so it's not good place to add code to monitor door status. Place code below in loop() and try if it works.
int doorValue = digitalRead(DOOR_PIN);
if (doorValue != lastDoorValue) {
Serial.println(doorValue);
esp.send(msgDoor.set(doorValue==0?0:1));
lastDoorValue = doorValue;}
The following user(s) said Thank You: mamg15

Please Log in or Create an account to join the conversation.

Time to create page: 0.476 seconds

Forum latest

  • No posts to display.