Tapatalk

Mail box project - limited knowledge

Mail box project - limited knowledge

3

PostMay 04, 2018#1

My idea is to place a reed switch (passive) in my mail box and have this trigger a push message. Is there a way to connect the base to a NodeMCU ESP8266 such as this one. I am thinking that the node and base will simply act as virtual wire that will send the reed switch state to a pin on the NodeMCU ESP8266.

I have tried following Thomas Lang's excellent tutorial here. After uploading the sketch to the ESP8266 and the Whisper Nodes as provided by Thomas I am receiving a message (even though I have not actually setup the distance sensor as Thomas has). My main problem is having the serial connection to the NodeMCU ESP8266 then connect to my WiFi network (i.e. coding).

I  tried this project using just ESP8266's however obviously I discovered the power problem. This project was shelved until I discovered the Whisper Node, I knew these were the answer so purchased 2 not really knowing how I was going to implement them.

I see in Mikes promotional video that there is a brief video of a mail box senor example that is exactly what I am trying to achieve.

 Any help will be greatly appreciated

Thank you.

313

PostMay 05, 2018#2

What is your goal in the use of the NodeMCU for/with your base station?  Are you taking the info, once it comes back in there and sending out something to the internet?

You can fairly easily setup a reed switch on an arduino device and read the value on it, determining if it is in an open or closed state.

Here is a chunk of code I have on my garage door project, it is actually on run off of a NodeMCU type product (no whispernode involved), but same general code should work on a whispernode with some changes to the pins):

int switchReedD1=5;
int switchReedD2=4;
int switchReedD7=13;
int doorswitchD6=12;

...

in the setup section:
  pinMode(switchReedD1, INPUT);
  pinMode(switchReedD2, INPUT);
  pinMode(doorswitchD6, OUTPUT);

...

(this is overkill for what you are doing, but just shows a few other pieces/parts)

  if (digitalRead(switchReedD1)==HIGH){
    doorstatus=0;  //closed
    lcd.print(0,0, "Door Closed                 ");
    Serial.println("Your Door is Closed");
  }
  else if (digitalRead(switchReedD2)==HIGH){
    doorstatus=1;  //open
    lcd.print(0,0, "Door Open                   ");
    Serial.println("Your Door is Open");
    }
  else if (digitalRead(switchReedD7)==HIGH){
    doorstatus=1;  //partial open
    lcd.print(0,0, "Door 5% Open               ");
    Serial.println("Your Door is Partially Open");
    }
  else
  {
    doorstatus=99;  //moving
    lcd.print(0,0, "Door Moving               ");
    Serial.println("Your Door is Opening/Closing");
  }

----

Assuming you have 2 whisper nodes, 1 in the mailbox as your node, a 2nd back in the house as your base station, you should be able to hook the whispernode up via serial to the nodemcu and send info to it that way, but really depends on what your goal is for the nodemcu.  Or are you trying to send directly from the external whispernode to the nodemcu?  If so the nodemcu you get would have to have a Lora or RFM69 chip on it, not something I've personally looked for.

As for the NodeMCU, are you going to be reading the remote mail box state and if it opens send an email, post something to a web page, etc because of it?  IE do you need some type of internet access and is that why you are adding the nodemcu into the mix here?   

For sharing information between the whispernode and another device, I'ver personally just tied into raspberry pi's and omega2's via the serial method.  Then had a python script on those devices to read the serial port for any data coming in.  When using the pi I had it logging the info into a db that graphed out the results (temperature gauge tracking).  In theory you should be able to have code running on the nodemcu that does something similar, read in the data that comes in over the serial connection and "do something" with it when you get it.

3

PostMay 06, 2018#3

First of all thank you for your comprehensive response :)

Yes I have 2 Whisper Nodes - base connected via serial to a NodeMCU ESP8266 ( I am trying to avoid the need to purchase a Pi)

As you suggest "In theory you should be able to have code running on the NodeMCU that does something similar, read in the data that comes in over the serial connection and "do something" with it when you get it." 

It's the "do something with it" that is where I am stuck - i.e. how to then have the NodeMCU connect to my WiFi network so that I can configure a Pushbullet notification to my Android device (I know how to code the Pushbullet notification aspect).

:)

313

PostMay 06, 2018#4

Sorry haven't specifically tried reading it in with a 8266, but quick google came up with this:

https://arduino.stackexchange.com/quest ... th-nodemcu

trimmed down version:
void loop()
{
 if (Serial.available())
 {
   int point = Serial.read();
   switch (point)
   {
     case 1:
       digitalWrite(5,HIGH); // Not !5 use High and Low
       break;
     case 2:
       digitalWrite(4,HIGH);
       break;
   }  // End of switch
 }  // End of if
 delay(50);  // I have no idea why, but most programs of this sort have a delay in.  (Hope someone explains to me too)
}  // End of function

---

typically I just do delay(1) so it can process other stuff if it has to. 

For me, when I'm doing serial reads on a linux device I typically read it in a character at a time instead of a full line.  I found I was having problems when reading full lines, but that may have been a pi issue and speed.  I also have the information I'm sending setup as semicolon delimited and look at the first section to make sure it is 88 or some "set" value to make sure I'm getting a full line of expected code and not just junk.  (88;v1;someIntValueForNumOfTimesThisIsI'veSentData;InterValueTemperature;UniqueId), then I just parse it and make sure it always is a full valid set of data based on the starting info.  Haven't added checksums or anything in it yet and I do the general checks on both the base station whispernode and the base station device I'm pushing to via serial just as an added check.

With the above example code, lets assume Case 1 = open, Case 2 = closed, in either case send potentially a different pushbullet notification (glad you know that part, means nothing to me).

Note:  You'll want to make sure you setup Serial.begin(X) to the same X value on both your WhisperNode and you ESP.  As noted in my Omega2 post earlier this week I have found that if you are getting junk, or dropping characters, to lower the speed down.  Since it is typically very small text and very infrequent, I'm going back to 9600 for most things.

As for getting your ESP setup, here is my whole garage project with my personal data removed, it was using blynk to push to my phone.  (original project from adafruit I think).  I was amazed how easy it was to tie into wireless using blynk, it handled all the work for me.  Took more time setting up the gui app in blynk for my phone app.

#include <ESP8266WiFi.h>

#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp8266.h>
char auth[] = "YourBlynkAuthCodeHere";

int switchReedD1=5;
int switchReedD2=4;
int switchReedD7=13;
int doorswitchD6=12;
int doorstatus=0;
int pinData=99;

const char* ssid     = "YourSSIDHere";
const char* password = "YourWirelessPasswordHere";

WidgetLCD lcd(V3);

void setup(){
  pinMode(switchReedD1, INPUT);
  pinMode(switchReedD2, INPUT);
  pinMode(doorswitchD6, OUTPUT);
  digitalWrite(doorswitchD6,LOW);
  Serial.begin(115200);

  Blynk.begin(auth, ssid, password);
  
}

BLYNK_WRITE(V2) 
{
  digitalWrite(doorswitchD6,HIGH);
  delay(500);
  digitalWrite(doorswitchD6,LOW);

  
  lcd.print(0,0, "Door Moving               ");
  
  int i=0;
  while (i == 0) {
    if (digitalRead(switchReedD7)==HIGH){
      i = 1;
    }
    delay(100);
    Serial.println("waiting....");
    lcd.print(0,0, "Door in Flux                 ");
  }
  
  digitalWrite(doorswitchD6,HIGH);
  delay(500);
  digitalWrite(doorswitchD6,LOW);
}

void loop(){
  Blynk.run();
  if (digitalRead(switchReedD1)==HIGH){
    doorstatus=0;  //closed
    lcd.print(0,0, "Door Closed                 ");
    Serial.println("Your Door is Closed");
  }
  else if (digitalRead(switchReedD2)==HIGH){
    doorstatus=1;  //open
    lcd.print(0,0, "Door Open                   ");
    Serial.println("Your Door is Open");
    }
  else if (digitalRead(switchReedD7)==HIGH){
    doorstatus=1;  //partial open
    lcd.print(0,0, "Door 5% Open               ");
    Serial.println("Your Door is Partially Open");
    }
  else
  {
    doorstatus=99;  //moving
    lcd.print(0,0, "Door Moving               ");
    Serial.println("Your Door is Opening/Closing");
  }

  delay(1000);
}


----

Anyway, hope that helps some.

PostMay 06, 2018#5

Something like this may be better (not tested):


void loop() {  
  if(Serial.available()>0)    //Checks is there any data in buffer
  {
    Info =Serial.read();  //Read serial data byte and send back to serial monitor
    If(Info='Open')  //This assumes you're just sending the phase "Open" each time it is Opened via serial.
    {
       DoSomething;
    }
    else
    {
       ThrowError;
    }
  }
  else
  {
    delay(1);                      /
  }
}

Depending on if you need to parse the string sent, a few tidbits here:
https://forum.arduino.cc/index.php?topic=336753.0

3

PostMay 06, 2018#6

Thank you once again for taking the time to help me with my project. Your information is very valuable to me. I will now take the time to digest it and apply your suggestions. I am learning some great stuff.

My project seemed simple enough however when I looked at the practicalities I realised I was out of my depth, however it is forcing me to learn which is a good thing.