www.homeseer.com    
 

Go Back   HomeSeer Message Board > HomeSeer Products & Services > HomeSeer General Discussion Area

HomeSeer General Discussion Area General discussion about HomeSeer that does not fall into any other category or are not specific to 1.x or 2.x versions of HomeSeer.

Reply
 
Thread Tools Display Modes
  #1  
Old April 3rd, 2016, 04:36 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Project weekend: Using MQTT with HS3

Spent this weekend doing a project using some old ARM boards I had around to start using MQTT to centralize my sensor data a bit from multiple sources. Sorry for the long post, but figured it may interest a few people here.

Currently I had data coming from a few places that I started with:

- 1-wire -> XapMCS1wire -> Xap -> Xap Plugin -> Homeseer
- Davis Weather station -> Weewx -> Wunderground, APRS-IS, *not* connected to Homeseer
- ESP8266 wifi boards I wanted to use (coming soon!)

Starting config:
- HS3 on Windows, running MQTT plugin from Updater (more details here http://www.domoticaforum.eu/viewforum.php?f=74)
- Weewx on a BeagleBone Black running Ubuntu

MQTT Server:
Coworker gave me a Raspberry Pi 2 he didn't need, so decided to use this for the MQTT server. Started with Linux Mint, removed the UI and installed Mosquitto server following these directions:
https://lukeisadog.wordpress.com/201...buntu-round-1/
Took literally 5mins to get running... was amazed how easy. Added auth support, but MQTT plugin in HS I don't see a way to do auth with it, so optional for now.

MQTT Plugin Initial Config:

Started with a simple config since my own internal network, and set the subscribe path to watch everything, "#, /#"

WeeWX:

This was actually a lot easier than I thought. I had already been pushing data to Wunderground and APRS-IS, but wanted to also be able to receive within HS. turns out there's a WeeWX plugin for MQTT:
https://github.com/weewx/weewx/wiki/mqtt

Changed setting in weewx.conf to match my server details, and within a few minutes starting seeing data on the MQTT server using the command:

Code:
mosquitto_sub -t \#
Output:
Code:
weather/monthET 0.0
weather/barometer_inHg 29.6840967742
weather/windrun_mile 0.0
weather/rainAlarm 0.0
weather/dayET 0.0
weather/interval_minute 1.0
weather/dewpoint_F 15.5842869329
1-Wire:
I've been using 1-wire for yeeaaars with XapMCS1wire and the MCSXap plugin (they work GREAT btw.) However lately wanted to try my hand at using OWServer, http://owfs.org/ so I could use some existing wiring going thru the house for Ethernet as a generic sensor network instead of just 1wire. (This is sort of what started this project off...) Plan is to add OWServers in the two key areas; attic and basement then reuse the existing cat5 going to attic for 1wire to be a normal LAN (chase pipe to attic is already pretty full...)

Right now I've started with the first server using an old Beagle Bone Black in the basement until I split the network into pieces. This BBB is running Ubuntu Server, with DS9490 USB plugged into the back. Installation of OWW was thru the normal Ubuntu packages, and set the config files using this post:
https://www.raspberrypi.org/forums/v...27379&p=505250

IMPORTANT NOTE: I'm not using OWFS but the OWServer Service ATM as not need for it. more on that in a moment.

1-Wire to MQTT Bridge:
This is where the magic happens... After some Google searches I found an OW Server to MQTT python script that did 90% of what I needed:
https://github.com/kylegordon/mqtt-owfs-temp

However it's a few years old, and only supported temperature sensors. It did support OWServer queries directly, so no need to do an OWFS local mount and parse it. I started doing some modifications, and forked my own version here:
https://github.com/mloebl/mqtt-owfs-temp

I added support for Humidity, Barometer and Illuminance sensors, including more complex pathing. Details on packages I needed to install are in the readme file within that repo. It's still only supports a few sensors, but wouldn't be hard to modify to add more as needed. Also seems to support sensors thru the Hobby Boards hub that are in the attic until I split it, so double bonus. This python script runs and queries the OWserver every 60s, and dumps to my MQTT server here:
Code:
/raw/owserver01/1-wire/1F.497F02000000/main/26.CDA721010000/humidity 45.8854
/raw/owserver01/1-wire/1F.497F02000000/main/10.F54D7C020800/temperature 41.25
/raw/owserver01/1-wire/26.09E39D000000/B1-R1-A/pressure 29.803598403
/raw/owserver01/1-wire/1F.497F02000000/main/26.CDA721010000/S3-R1-A/illuminance 65.8839
Data Aggregation Within Homeseer3:
The MQTT plugin makes this pretty easy. You can easily subscribe to MQTT topics thru their subscription options. You can see the topic paths using the mosquitto_sub I mentioned above:




Current Configuration:
- HS3 on Windows, running MQTT plugin connected to MQTT server
- Mosquitto MQTT server running Ubuntu
- Davis Weather station-> Weewx Server on Ubuntu Server-> WeeWX MQTT Plugin->MQTT Server
- 1-wire ->OWFS OWServer on Ubuntu -> Python MQTT Script running as a service->MQTT Server

Going to run with this for a couple weeks and see how it does. We've used MQTT at work for some past projects, but first time I've gotten my hands dirty with it. Pretty happy with the results so far and was amazed how easy it was. Worst part of the project, that I left out above, was when I reused an IP addressed from an old server that apparently had powered on by accident... So spent 2 days trying to figure out why some things could connect and others couldn't to the MQTT server... oops
Reply With Quote
  #2  
Old April 3rd, 2016, 05:08 PM
sparkman's Avatar
sparkman sparkman is offline
OverSeer
 
Join Date: Oct 2001
Location: Calgary, Alberta, Canada
Posts: 6,004
Thanks for the great write-up. I am also considering installing an MQTT server on a pi. Any reason you went with Mint rather than the standard Raspbian?

Cheers
Al
__________________
HS3Pro 3.0.0.318 on Jetway JBC501F9Q-Q87-B i7 8GB 1874 Devices, 955 Events, 28 Plugins
Z-Wave 3.0.1.131 Z-Net 105 nodes:Leviton Vizia,Kwikset,FortrezZ Valve/Sensors,Everspring Sensors/Modules/Outlets,CT30 Stats,MIMOLites,Aeotec Smart Switches
RFXCom W800,RFXrec433,RFXtrx433|APCUPSD|Pushover|Squeezebox|weatherXML|HS Phone W2C|APCUPSD|UltraLog
UltraGCIR GC-100|UltraNetcam|UltraPioneer|Ultra1Wire|DSC PC1832|BLLED|BLTVGuide|ImperiHome|jon00 Utilities|MySensors

PHLocation|X10 CM11A IOLinc,etc
Reply With Quote
  #3  
Old April 3rd, 2016, 05:16 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Quote:
Originally Posted by sparkman View Post
Thanks for the great write-up. I am also considering installing an MQTT server on a pi. Any reason you went with Mint rather than the standard Raspbian?

Cheers
Al

No other reason than I prefer Ubuntu... basically removing the GUI and installing the server package set gives you an Ubuntu server ready to go
Reply With Quote
  #4  
Old April 3rd, 2016, 05:28 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Another minor note, I'd probably run Mosquitto MQTT server on my HS3 box if it was running linux. Unfortunately ADIO-100 plugin doesn't work on Linux, so stuck with Windows for now.
Reply With Quote
  #5  
Old April 4th, 2016, 07:20 AM
TomTom's Avatar
TomTom TomTom is offline
Seer Master
 
Join Date: Apr 2012
Location: USA
Posts: 1,412
Thanks


Sent from my iPhone
__________________
Tom
baby steps...starting again with HS3
HS3Pro: Z-NET & 80 Z wave Devices,
HSTouch: 4 Joggler (Android Kitkat), 2 iPhone, 3 iPads
Whole House Audio: 5 SqueezePlay Jogglers w Bose Speakers
In The Works: 10 Cameras Geovision, new Adecmo/Envisalink Alarm, Arduinos
System: XP on Fanless Mini-ITX w/ SSD
Reply With Quote
  #6  
Old April 9th, 2016, 07:07 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Another update...

This weekend got an Arduino Yun, loaded up the Adafruit MQTT sample application, and testing replacing my ADIO-100 with this instead. Took maybe an hour of coding and super easy. Waiting for a terminal blocker header and will test it out with the Dakota Wireless Receiver

The other thing I did today was write a Python script to read my TED1000 and post it to MQTT, it's based on this script; http://svn.navi.cx/misc/trunk/python/ted.py

If anyone's interested, I can write it up and post it as well:
Code:
/raw/arm.localdomain/ted1000/house_code 69
/raw/arm.localdomain/ted1000/HiVrmsMtd 139.7
/raw/arm.localdomain/ted1000/kwH_month 921.142417562
/raw/arm.localdomain/ted1000/volts 120.5
/raw/arm.localdomain/ted1000/kwH_today 32.1682731003
/raw/arm.localdomain/ted1000/kw 1.33
/raw/arm.localdomain/ted1000/HiVrmsTdy 122.7
/raw/arm.localdomain/ted1000/LoVrmsMtd 113.6
/raw/arm.localdomain/ted1000/LoVrmsTdy 118.5
/raw/arm.localdomain/ted1000/house_code 69
/raw/arm.localdomain/ted1000/HiVrmsMtd 139.7
/raw/arm.localdomain/ted1000/kwH_month 921.142417562
/raw/arm.localdomain/ted1000/volts 120.5
/raw/arm.localdomain/ted1000/kwH_today 32.1682731003
/raw/arm.localdomain/ted1000/kw 1.34
/raw/arm.localdomain/ted1000/HiVrmsTdy 122.7
/raw/arm.localdomain/ted1000/LoVrmsMtd 113.6
/raw/arm.localdomain/ted1000/LoVrmsTdy 118.5
About an hour to reflash and configure an old Beagle Bone, and then another hour or so of coding. Polls the TED 1000 unit every second vs the Aeon Labs I was looking to put in that I believe is every minute?
Reply With Quote
  #7  
Old April 10th, 2016, 09:56 AM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
For those at some point in the future who find this post... here's the github repo for getting MQTT running with TED1000 and posting energy to HS every seconds:

https://github.com/mloebl/mqtt-ted1000
Reply With Quote
  #8  
Old April 24th, 2016, 10:54 AM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Friday night started playing with some NodeMCU ($9 from Amazon) and DHT22 sensors. NodeMCUs are ESP8266 wifi modules with a built in USB connector, power supply and break out pins. Makes it super easy to program them vs the stand alone ESP8266 modules. Using a couple Arduino sketch examples from Adafruit and the Arduino IDE, I created relatively cheap Wifi temp/humidity sensors I can put around the house.
Code:
/raw/nodemcu01/humidity 34.80
/raw/nodemcu01/temperature 67.64
Also officially eliminated my ADIO-100 as well for the driveway sensors using the Arduino Yun connected to my Dakota Wireless receiver. Events come in ~1s of the contact vs delayed before (and no more errors in the log!) Using a PoE module on the Yun to power it, and pretty cool as can upload configuration changes via Wifi or ethernet if required (didn't realize it did this, good job Arduino.cc on that one!)

If you seriously haven't checked out MQTT... definitely worth a few minutes. The fact it works with so many devices and languages, it's pretty darn cool
Reply With Quote
  #9  
Old April 24th, 2016, 02:22 PM
TomTom's Avatar
TomTom TomTom is offline
Seer Master
 
Join Date: Apr 2012
Location: USA
Posts: 1,412
Reading your excellent progress is driving me nuts in that I just need to find time to do this. Your work opens up a whole new path to sensors.
Which poe module did you use or where did you buy it.


Sent from my iPhone
Reply With Quote
  #10  
Old April 24th, 2016, 02:36 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Quote:
Originally Posted by TomTom View Post
Reading your excellent progress is driving me nuts in that I just need to find time to do this. Your work opens up a whole new path to sensors.
Which poe module did you use or where did you buy it.


Sent from my iPhone
I had the same feelings as well which is what got me so excited about it. I finally split my 1-wire network as well this weekend, so have a Pi owfs 1wire server in the basement, and a second one up in the attic now. I had been looking at the Arduino plugins, and the MySensors ones as well. However this ended up sort of eliminating that need for me.

I couldn't find a PoE module on Amazon that worked, but this one seems to work:
http://www.ebay.com/itm/201395723489

A slight hum when plugged in, but working ok.

Really only "issue" I have found so far is the MQTT plugin seems to set the status/value kind of weird. If I send the "Off" string, HS updates beautifully, but I can't use that for events like I wanted. If I send a "0" instead, works great for events, but then it won't let me change the device string to "Off" thru the device settings. I'll probably ping the author about it to see if he has some ideas. Same sorta deal with formatting the numbers so not 8 digits long

But overall it seems to be working pretty well. HS3/MQTT/TED1000 seem to have no problems with my 1s updates on the power monitor either.
Reply With Quote
  #11  
Old April 30th, 2016, 11:50 AM
TomTom's Avatar
TomTom TomTom is offline
Seer Master
 
Join Date: Apr 2012
Location: USA
Posts: 1,412
So seeing the great work Mike's done inspired me to get on it. Let me just say it took me more than 5min that it took Mike . For Linux noob like me it took me 3-4 hours just because I had forgotten a lot of things from my previous dealing with linux and pi.

Using Mike's links above, I've come up with a set of Hand Holding Instructions that should get your MQTT server up without much thought.

1. Download Ubuntu for PI 2 or 3:
https://ubuntu-mate.org/raspberry-pi/

2. Unzip the downloaded Ubuntu .xz file using 7-zip:
http://www.7-zip.org/download.html
Now you'll have a .img file

3. Use Win32DiskImager to burn the image, .img file, on to SD card(minimum 8GB)

4. Insert your SD card, and boot up your Ubuntu Pi.
You will need to setup username, computer name, and password.

5. Use the Mate Terminal software on your Ubuntu Pi( Applications > System Tools > Mate Terminal) for the rest of the instructions. Remember to connect your HDMI cable to a monitor for this.
OR
For Remote Access Your Ubuntu Pi. See Remote Access Option(below).

6. If your using Mate Terminal on your Ubuntu Pi then go to
Applications > System Tools > Mate Terminal
Type the following:

MQTT Install Instruction:

Code:
sudo apt-get install python-software-properties

sudo apt-get install software-properties-common


sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

sudo apt-get update

sudo apt-get install mosquitto

sudo apt-get install mosquitto-clients
Well your done setting up your Ubuntu Pi MQTT Server!! Thanks Mike!!


---------------------------------------------------------------------
Remote Access Option
- To remote access your Ubuntu Pi - Install OpenSSH to get SSH to Access to your Pi.
On your Ubuntu Pi go to Applications > System Tools > Mate Terminal
Type the following:
Code:
sudo apt-get install openssh-server
This will allow you to get SSH Access of you Ubuntu Pi.
Now Use Putty on your PC to access your Ubuntu Pi.
Then follow MQTT Install Instruction(above)

I'm stopping for now. Will tackle HS3 Setup and rest after I get my Yun.

Last edited by TomTom; May 24th, 2016 at 05:01 PM.
Reply With Quote
  #12  
Old April 30th, 2016, 01:44 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
@TomTom: Nice! Sorry I guess I could have put a few more details for people I use Linux a lot with my day job, so take a lot of it for granted.

I got an inexpensive esp8266 talking to it as well, though hitting a power limitation on the USB adapter i was using, so the readings from the DHT22 were intermittent from that one. The nodemcu however has been rock solid. Hoping to get an enclosure printed it out so I can mount it. I managed to put on a light web server on it as well for tracking sensor data:

Code:
Humidity (%): 33.70
Temperature (°C): 20.20
Temperature (°F): 68.36
VCC Voltage (volts): 2.943
This weekend I attempted to get ssl running on 8883 with certs, but not going well for the clients. Seeing if I can get owntrack to communicate with it.
Reply With Quote
  #13  
Old May 1st, 2016, 09:37 AM
Pete's Avatar
Pete Pete is online now
OverSeer
 
Join Date: Jan 2001
Location: House
Posts: 14,670
Very nice Mike!

How are your DHT22 numbers comparing to the old one wire Honeywell HIH-3605?

Yup; here still on the older Temp05 and Temp08 1-Wire devices (well and xAP) originally installed in a star topology (which today is wrong).

Lately here have been purchasing everything from Amazon Prime. It is that 2-day stuff that I like. Noticed the WiFi Module - ESP8266 for around $3 with free shipping on Ebay.
__________________
- Pete

Automator


Hardware | Haswell Intel iSeries 3 - 16Gb | Pine64 - 2Gb computers

HS3 Pro & Lite
Edition Beta 3.0.0.398 | Ubuntu 16.04 64 bit | Oracle Windows Virtual Box ==> for Wintel only SAPI and HS3 plugins

HS3 Plugins - a bunch
Light switches - X10,UPB, ZWave and Zigbee
Speech - Microsoft SAPI - Neospeech - Amazon Echo
Security - Leviton HAI Omni Pro 2
Weather - Davis Vantage Vue - MeteoStick
Firewall - PFSense
CCTV - Zoneminder

Audio - Russound - AB8SS

Reply With Quote
  #14  
Old May 1st, 2016, 10:13 AM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Quote:
Originally Posted by Pete View Post
Very nice Mike!

How are your DHT22 numbers comparing to the old one wire Honeywell HIH-3605?
Not too bad at all. I have it a few feet away from it the Davis weather station console, which also monitors indoors. The DHT22 is usually pretty close to that as well.
Reply With Quote
  #15  
Old May 1st, 2016, 10:16 AM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Here's the sample ESP8266/NodeMCU Arduino sketch I am using:

Code:
/***************************************************
  Adafruit MQTT Library Arduino Yun Example

  Make sure your Arduino Yun is connected to a WiFi access point which
  has internet access.  Also note this sketch uses the Console class
  for debug output so make sure to connect to the Yun over WiFi and
  open the serial monitor to see the console output.

  Works great with the Arduino Yun:
  ----> https://www.adafruit.com/products/1498

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Tony DiCola for Adafruit Industries.
  MIT license, all text above must be included in any redistribution

 **************************************************
 
 Adapted for the ESP8266 Boards
 
 This is also using the Adafruit DHT libraries which can be downloaded
  from GitHub:
  https://github.com/adafruit/DHT-sensor-library

 ****************************************************/

#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include "DHT.h"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "MQTT_SERVER_REPLACE"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "optional_username_replace"
#define AIO_KEY         "optional_password_replace"
#define AIO_FEEDNAME    "/raw/nodemcu"  # Change this to what you may want to use

/************ Global State (you don't need to change this!) ******************/

 #define DHTPIN 4     // NodeMCU
// #define DHTPIN 2     // ESP8266
#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321

DHT dht(DHTPIN, DHTTYPE);
ADC_MODE(ADC_VCC);

WiFiClient client;
WiFiServer server(80);

// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;
const char MQTT_FEEDNAME[] PROGMEM  = AIO_FEEDNAME;

const char* ssid     = "ssid_replace";
const char* password = "password_replace";



const int delaytime = 10000;
int loop_counter = 10;
float humidity = 0;
float temp_f = 0;
float temp_c = 0;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

const char HUMIDITY_FEED[] PROGMEM = AIO_FEEDNAME "/humidity";
const char TEMPERATURE_FEED[] PROGMEM = AIO_FEEDNAME "/temperature";
const char VOLTAGE_FEED[] PROGMEM = AIO_FEEDNAME "/volts";

Adafruit_MQTT_Publish humiditySensor = Adafruit_MQTT_Publish(&mqtt, HUMIDITY_FEED);
Adafruit_MQTT_Publish temperatureSensor = Adafruit_MQTT_Publish(&mqtt, TEMPERATURE_FEED);
Adafruit_MQTT_Publish voltageSensor = Adafruit_MQTT_Publish(&mqtt, VOLTAGE_FEED);

// Setup a feed called 'onoff' for subscribing to changes.
// const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";

// Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);

/*************************** Digital Input Pins *****************************/

/*************************** Sketch Code ************************************/



void setup() {

  Serial.begin(115200);
  delay(100);
 
  // We start by connecting to a WiFi network
 
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
   
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
 
  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
  
  // Bridge.begin();
  
  Serial.println(F("MQTT Server"));
  server.begin();
  // Setup MQTT subscription for onoff feed.
  // mqtt.subscribe(&onoffbutton);

}

// uint32_t x=0;


void loop() {
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();



  // ping the server to keep the mqtt connection alive
  if(! mqtt.ping()) {
    Serial.println(F("MQTT Ping failed."));
  }

 // delay(200);

  float h = 0;
  // Read temperature as Celsius (the default)
  float t = 0;
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = 0;

  // Get ADC voltage
  float v = ((float)ESP.getVcc() / 1000);
  
  if (loop_counter == 10)
  {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.println(" *F\t");
  
  }
  

  humidity = h;
  temp_f = f;
  temp_c = t;
  humiditySensor.publish(h);
  temperatureSensor.publish(f);
  voltageSensor.publish(v);
  
  loop_counter = 0;
  
  }


  WiFiClient client = server.available();
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println("Connection: close");  // the connection will be closed after completion of the response
  client.println("Refresh: 10");  // refresh the page automatically every 5 sec
  client.println();
  client.println("<!DOCTYPE html>");
  client.println("<html xmlns='http://www.w3.org/1999/xhtml'>");
  client.println("<head>\n<meta charset='UTF-8'>");
  client.println("<title>ESP8266 Temperature & Humidity DHT11 Sensor</title>");
  client.println("</head>\n<body>");
  client.println("<H2>ESP8266 & DHT22 Sensor</H2>");
  client.println("<H3>Humidity / Temperature</H3>");
  client.println("<pre>");
  client.print("Humidity (%): ");
  client.println((float)humidity, 2);
  client.print("Temperature (°C): ");
  client.println((float)temp_c, 2);
  client.print("Temperature (°F): ");
  client.println((float)temp_f, 2);
  client.print("VCC Voltage (volts): ");
  client.println((float)v, 3);
  client.println("</pre>");
  client.print("</body>\n</html>");

  loop_counter++;
  delay(1000);
}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT server" + String(AIO_SERVER) + " on port " + String(AIO_SERVERPORT) + "... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Serial.println(mqtt.connectErrorString(ret));
       Serial.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");

  
}
Reply With Quote
  #16  
Old May 1st, 2016, 10:17 AM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Here's the Arduino Yun sketch I am using for the driveway sensors connected to the Dakota Wireless unit:

Note I have not yet added the web server like I did above, but wouldn't be too hard to modify.

Code:
/***************************************************
  Adafruit MQTT Library Arduino Yun Example

  Make sure your Arduino Yun is connected to a WiFi access point which
  has internet access.  Also note this sketch uses the Console class
  for debug output so make sure to connect to the Yun over WiFi and
  open the serial monitor to see the console output.

  Works great with the Arduino Yun:
  ----> https://www.adafruit.com/products/1498

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Tony DiCola for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
#include <Bridge.h>
#include <Console.h>
#include <YunClient.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"


/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "MQTT_SERVER_REPLACE"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "optional_username_replace"
#define AIO_KEY         "optional_password_replace"
#define AIO_FEEDNAME    "/raw/arduino01/driveway"

/************ Global State (you don't need to change this!) ******************/

// Create a YunClient instance to communicate using the Yun's brighe & Linux OS.
YunClient client;

// Store the MQTT server, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;
const char MQTT_FEEDNAME[] PROGMEM  = AIO_FEEDNAME;


// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);

/****************************** Feeds ***************************************/

const char VEHICLESENSOR_FEED[] PROGMEM = AIO_FEEDNAME "/vehicle";
const char MOTIONSENSOR_FEED[] PROGMEM = AIO_FEEDNAME "/motion";
const char MAILBOXSENSOR_FEED[] PROGMEM = AIO_FEEDNAME "/mailbox";

// Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);

Adafruit_MQTT_Publish vehicleSensor = Adafruit_MQTT_Publish(&mqtt, VEHICLESENSOR_FEED);
Adafruit_MQTT_Publish motionSensor = Adafruit_MQTT_Publish(&mqtt, MOTIONSENSOR_FEED);
Adafruit_MQTT_Publish mailboxSensor = Adafruit_MQTT_Publish(&mqtt, MAILBOXSENSOR_FEED);


// Setup a feed called 'onoff' for subscribing to changes.
// const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";

// Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);

/*************************** Digital Input Pins *****************************/
int VehicleSensor_Pin = 8;
int MotionSensor_Pin = 9;
int MailboxSensor_Pin = 10;

/*************************** Sketch Code ************************************/

void setup() {
  Bridge.begin();
  Console.begin();
  Console.println(F("MQTT Server"));

  pinMode(VehicleSensor_Pin, INPUT);
  pinMode(MotionSensor_Pin, INPUT);
  pinMode(MailboxSensor_Pin, INPUT);

  digitalWrite(VehicleSensor_Pin, LOW);   
  digitalWrite(MotionSensor_Pin, LOW);   
  digitalWrite(MailboxSensor_Pin, LOW);   
  // Setup MQTT subscription for onoff feed.
  // mqtt.subscribe(&onoffbutton);
}

// uint32_t x=0;

uint32_t vehicleSensorSet = 0;
uint32_t motionSensorSet = 0;
uint32_t mailboxSensorSet = 0;

void loop() {
  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

 if (digitalRead(VehicleSensor_Pin) == HIGH && vehicleSensorSet == 0) 
 {
   Serial.println ("Vehicle Sensor Trigged");
   vehicleSensorSet = 1;
  if (! vehicleSensor.publish("1")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }
 
if (digitalRead(VehicleSensor_Pin) == LOW && vehicleSensorSet == 1) 
 {
  vehicleSensorSet = 0;
  if (! vehicleSensor.publish("0")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }
 
 
 if (digitalRead(MotionSensor_Pin) == HIGH && motionSensorSet == 0) 
 {
   Serial.println ("Motion Sensor Trigged");
   motionSensorSet = 1;
  if (! motionSensor.publish("1")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }

 if (digitalRead(MotionSensor_Pin) == LOW && motionSensorSet == 1) 
 {
   motionSensorSet = 0;
  if (! motionSensor.publish("0")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }


 
  if (digitalRead(MailboxSensor_Pin) == HIGH && mailboxSensorSet == 0) 
 {
   Serial.println ("Mailbox Sensor Trigged");
   mailboxSensorSet = 1;
  if (! mailboxSensor.publish("1")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }
 
 if (digitalRead(MailboxSensor_Pin) == LOW && mailboxSensorSet == 1) 
 {
  mailboxSensorSet = 0;
  if (! mailboxSensor.publish("0")) 
  {
    Console.println(F("Failed"));
  } else 
  {
    Console.println(F("OK!"));
  }
 }


  // ping the server to keep the mqtt connection alive
  if(! mqtt.ping()) {
    Console.println(F("MQTT Ping failed."));
  }

  delay(200);

}

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Console.print("Connecting to MQTT server" + String(AIO_SERVER) + " on port " + String(AIO_SERVERPORT) + "... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
       Console.println(mqtt.connectErrorString(ret));
       Console.println("Retrying MQTT connection in 5 seconds...");
       mqtt.disconnect();
       delay(5000);  // wait 5 seconds
  }
  Console.println("MQTT Connected!");

  
}
Reply With Quote
  #17  
Old May 1st, 2016, 02:13 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Found an Arduino Yun mount on Thingaverse, and modified ito so it can be mounted in a Leviton SMC enclosure... not the best print, but works:



Part can be downloaded here: http://www.thingiverse.com/thing:1533513
Reply With Quote
  #18  
Old May 1st, 2016, 07:18 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
So I officially put the Arduino Yun in place and wired up to my driveway sensor in the basement. For some reason the PoE module wasn't happy with the switch in the basement, so running USB powered for now until I debug that. However nice to get this out of the way and mounted:


Quick test of the driveway sensors and the mailbox and motion sensing inputs are working. Guess I'll find out tomorrow how the vehicle sensor works when I drive out to work
Reply With Quote
  #19  
Old May 1st, 2016, 07:31 PM
TomTom's Avatar
TomTom TomTom is offline
Seer Master
 
Join Date: Apr 2012
Location: USA
Posts: 1,412
Nice! How far was the yun from power source using the poe?


Sent from my iPhone
Reply With Quote
  #20  
Old May 1st, 2016, 07:33 PM
mloebl's Avatar
mloebl mloebl is offline
Seer Master
 
Join Date: Apr 2002
Location: Northern, MA
Posts: 784
Quote:
Originally Posted by TomTom View Post
Nice! How far was the yun from power source using the poe?


Sent from my iPhone
Not far at all... maybe 12" Was trying a really short cable to see (maybe also part of the problem). TBH I really don't need PoE in the SMC as have a power strip in there. It tested fine upstairs in my office on a different switch and a different PoE injector so a few different variables here.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HS3 MQTT Plugin ghurk Script & Plug-In Library 12 February 27th, 2017 07:21 PM
[c#.Net] MQTT plugin dmurphy Script & Plug-In Library 9 June 12th, 2016 09:13 PM
How to restore HSTouch project from iPhone/iDevice if project is lost Rupp Clients - Apple iPhone/iPod/iPad 7 March 15th, 2016 05:51 PM
HS3 Project Deploy is overwriting HS2 Project Config ksdehoff HS3Touch General Discusion 0 March 12th, 2014 10:29 PM


All times are GMT -4. The time now is 11:30 AM.


Copyright HomeSeer Technologies, LLC