@Yveaux I am so terribly embarrassed! In order to rule out something wrong with the WS5100 I rebuilt the GW using an old Arduino UNO with an Ethernet shield. Still same problem. Then to really make sure I pasted/copied username and password from the cloudmqtt into the sketch. Immediate success! It turned out that I had misread an uppercase I (indigo) for a lower case l (lima). Still the suggestions from the community were good since I could iron out one possible cause after another. Thanks for the support!
Best posts made by bgunnarb
-
RE: [SOLVED] Cannot get GwWS5100MQTT to connect to cloudmqtt.com
-
3D printed housing for an MQTT-GW
I recently designed a housing for my MQTT-Gateway, based on an ESP8266 module (Node-MCU) and an nRF24L01+PA+LNA. The housing printed great using PLA on my FF Creator Pro. Connections are made using Dupont cables cut in half and soldered directly to the nRF24 where the pins have been removed. I enclose a picture from FreeCad and a link to the stl-files on Github for the base and the cover.
-
RE: Battery life for Motion Sensor
Hi!
Sorry to say, but the Arduino Nano may not be the best choice for battery operation and maybe the Motion Detector also is not the most power economic application. I guess, to start with you have not done any modification to the Nano like removing the power LED? There goes a few milliamps the whole time.The PIR need rather high voltage to be stable and not generate random detects. I run mine on 8V. But the Nano needs only 5V so you burn off a bit of power in the voltage regulator chip, even if the sleep current of the Nano is very low. Of course, the more detections there are, the more power is used during the day.
The Arduino ProMini is a better choice for battery operation. Please see Battery Powering in the left-hand column on the MySensors site. There are a few tricks there to really bring down power consumption. Then again the PIR needs more than 5V so you will have to use a power booster if you use the ProMini 8 MHz version that runs on 3.3 V.
I think sleeping for 600000 mS will only marginally improve battery economy. I went through the same ordeal as you and I run my Motion Detector on a 9 V wall-wart.
For sensors that really work well on battery I would suggest Light, Temperature and Humidity. I have a few of these built around ProMini 8 MHz and they typically run for 9 months or more on 2 x AA reporting every 2 minutes, but if you look at the link above, people achieve much better results. But I'm happy with 9 months.
Best of luck and keep experimenting!
-
RE: DHT11 Example Code on Arduino
I think the reason is that you have not set a node ID. At least this is not visible in the sketch.
OpenHab does not hand out node IDs. I have good experience.
You should try setting
#define MY_NODE_ID 1
In the beginning of your sketch where you define Child ID. -
RE: 💬 Atmospheric Pressure Sensor
Hi!
I had exactly the same problem until I realised I had compiled for the 8 MHz version of the Arduino Pro Mini instead of the 16 MHz version.
Also, recently building an humidity sensor I realised there are no pull-up resistors on the SDA SDL lines, but that should be built-in if you use a break-out module. -
RE: How to calibrate a gauge sensor
@pierrot10
Since I am using almost the same tipping bucket rain gauge, let me try to explain how it works:The top of my funnel measures 109 x 49 mm = 5341 mm2 (square millimeters). For now, let us not worry about the rounded corners of the funnel.
If it rains 1 mm the funnel will collect 5341 mm3 (cubic millimeters) which is 5,341 cubic centimeters equal to 5,34 milliliters. This is difficult to use for calibration so let's try with 10 mm of rain which then equals 53,4 milliliters or 0,53 deciliters of water.So, you pour 53,4 milliliters of water into the funnel, not spilling any and you count the number of bucket tips. In my example, when I do this, the bucket tips 30 times. So if the bucket tips 30 times during a time period, it has rained 10 mm during that time. Or, the other way around: One tip of the bucket = 10/30 = 0,33 mm of rain.
Do not worry about the size of the bucket inside. What matters is how many times the bucket tips for a given amount of water. It is the area of the funnel which is important.
When it rains 1 mm an area of one square meter will receive 1 liter of water but the little funnel will only receive 5,34 milliliters as explained above.Now, if you really want to be accurate, you should take away the area of the rounded corners. But that will be less than 0,5% and there are other sources of inaccuracy.
-
RE: DHT11 Example Code on Arduino
Oops! I may have misled you.
The #define MY_NODE_ID 1 has to go into the sketch before you call #include <MySensors.h>as pointed out in the description of the Library API definitions:
"Remember to set configuration defines before including the MySensors.h."
In my sketches I always do all the #define (s) first like below:// Enable debug prints to serial monitor #define MY_DEBUG #define MY_NODE_ID 23 #define BATTERY_SENSE_PIN A0 // Input pin for battery sense #define VMIN 1.0 // (Min input voltage to regulator according to datasheet or guessing. (?) ) #define VMAX 3.22 // (Known or desired voltage of full batteries. If not, set to Vlim.) #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <AM2320.h> #include <Wire.h> #include <MySensors.h> // Rest of code goes here...
-
RE: MQTT GW issues with sending MQTT msg
Did you try MQTT.fx? I use that SW (free of charge) a lot when troubleshooting MQTT.
Start by checking that MQTT.fx really does connect with the MQTT broker. Then subscribe first to the topic #, which means everything. Then narrow down by subscribing to mygateway1-out/# and so on.
The latest version of MQTT.fx also has a Topics Collector that shows all topics on the broker as they arrive.
-
RE: How to calibrate a gauge sensor
@pierrot10
1 mm of rain over 1 square meter is 1 liter of water. Correct!
One liter makes 358 tips so one tip is then 2,7932 milliliters that is correct.
But rainfall mm/hr is 2,7932 * nbr of tips only if the area of the funnel is 1 square meter.Your funnel is only 55 square centimeters so you will only collect 55/10000 of the rain that falls on the whole square meter.
The example you are using at the top of your post does not have the size of the funnel anywhere in the code.
-
RE: Board and hardware failures
@ileneken3 and @sundberg84
Hi!
I agree with @sundberg84 , the only time I have had problems, and that is only once, is when I had a very noisy DC/DC booster connected. It took an extra 22uF capacitor at the output of the booster to get the radio to connect to the GW. The booster generated spikes of more than 150 mV peak. I connected the capacitor in the experimental area where Vcc and GND are available. I also switched the capacitor close to the radio to 22uF instead of 4.7 uF. For my next design, I will make sure to connect the radio directly to 2xAA as suggested many times -
RE: Bad downlink radio solved by updating gateway
Ah! Sorry, misprint. Now using 2.2.0, not 2.0.0!
-
Motion detector with temperature and barometer function
I have built an intrusion detector that also measures barometer pressure and indoor and outdoor temperatures.
The pressure and indoor temperature is measured by a BMP280 and a number of DS18B20 sensors can be connected to measure the temperature in remote locations.
When movement is detected two red LEDs flash during 20 sec.
Everything is built into a frightening wooden mask, bought in Indonesia. The LEDs poke out through the nostrils.
Here is the sketch:
/** * File name: MotionSensor_LED_2_temp_baro_280 * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * Version 2.1 - Gunnar Blockmar includes PMB280 temp/baro sensor and DS18B20 temp sensor * * DESCRIPTION * Motion Sensor example using HC-SR501 * http://www.mysensors.org/build/motion * * Now with 1 fading LEDs when sensor is triggered * Measuring temp and pressure with BMP 280. Local pressure * Measuring remote temp via DS18B20 */ #include <Adafruit_BMP280.h> #include <Adafruit_Sensor.h> #include <OneWire.h> #include <DallasTemperature.h> #include <SPI.h> unsigned long SLEEP_TIME = 60000; // Sleep time between reports (in milliseconds) #define MY_DEBUG #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!) #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID_MOT 0 // Id of the motion sensor child #define CHILD_ID_ITEMP 1 // Id of indoor temperature sensor #define CHILD_ID_BARO 2 // Id of pressure sensor #define CHILD_ID_OTEMP 3 // Id of outdoor temperature sensor #define RED_LED 5 // Pin for LED #define RED_LED2 6 // Pin for LED2 #define DELAY 40 // Wait for brightness change int fadeAmount = 5; // brightness change per step #define ONE_WIRE_BUS 2 // Pin where dallas sensor is connected #define MAX_ATTACHED_DS18B20 16 OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. int numSensors=0; bool receivedConfig = false; const char *weather[] = { "Stabilt", "Bättre", "Sämre", "Ostadigt", "Åska!", "Okänt" }; enum FORECAST { STABLE = 0, // "Stable Weather Pattern" SUNNY = 1, // "Slowly rising Good Weather", "Clear/Sunny " CLOUDY = 2, // "Slowly falling L-Pressure ", "Cloudy/Rain " UNSTABLE = 3, // "Quickly rising H-Press", "Not Stable" THUNDERSTORM = 4, // "Quickly falling L-Press", "Thunderstorm" UNKNOWN = 5 // "Unknown (More Time needed) }; Adafruit_BMP280 bmp; // Digital Pressure Sensor float lastPressure = -1; float lastTemp = -1; int lastForecast = -1; const int LAST_SAMPLES_COUNT = 5; float lastPressureSamples[LAST_SAMPLES_COUNT]; // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm // get kPa/h by dividing hPa by 10 #define CONVERSION_FACTOR (1.0/10.0) int minuteCount = 0; bool firstRound = true; // average value is used in forecast algorithm. float pressureAvg; // average after 2 hours is used as reference value for the next iteration. float pressureAvg2; float dP_dt; // Enable debug prints to serial monitor // #define MY_DEBUG // Enables and select radio type (if attached) #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #define MY_NODE_ID 41 #include <MySensors.h> // Initialize motion message MyMessage msgm(CHILD_ID_MOT, V_TRIPPED); // Initialize temp baro and forecast messages MyMessage msgit(CHILD_ID_ITEMP, V_TEMP); MyMessage msgp(CHILD_ID_BARO, V_PRESSURE); MyMessage forecastMsg(CHILD_ID_BARO, V_FORECAST); MyMessage msgot(0, V_TEMP); bool metric = true; void before() { // Startup up the OneWire library sensors.begin(); } void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input pinMode(RED_LED, OUTPUT); // sets the pin for the LEDs as output pinMode(RED_LED2, OUTPUT); analogWrite(RED_LED, 0); // make sure LEDs are OFF analogWrite(RED_LED2, 0); bmp.begin(); if (!bmp.begin()) { Serial.println("Could not find a valid BMP280 sensor, check wiring!"); while (1) {} } // requestTemperatures() will not block current thread sensors.setWaitForConversion(false); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("M. Sens_LED_2t/b/f 280", "2.2"); // Fetch the number of attached temperature sensors numSensors = sensors.getDeviceCount(); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_MOT, S_MOTION); present(CHILD_ID_ITEMP, S_TEMP); present(CHILD_ID_BARO, S_BARO); for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { present(i+CHILD_ID_OTEMP, S_TEMP); } } void loop() { // Read digital motion value boolean tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH; Serial.println(tripped); send(msgm.set(tripped?"1":"0")); // Send tripped value to gw if (tripped) { int brightness = 0; // brightness of LED int count = 0; // number of half cycles to fade LED while (count < 12) { // run 6 full fade cycles analogWrite(RED_LED, brightness); analogWrite(RED_LED2, brightness); brightness = brightness + fadeAmount; if (brightness == 0 || brightness == 255) { fadeAmount = -fadeAmount; // change direction of fade count ++; } wait (DELAY); //wait to see brightness change } analogWrite(RED_LED, 0); // turn off LEDs analogWrite(RED_LED2, 0); } int long pressure = bmp.readPressure() / 100; float temperature = bmp.readTemperature(); int forecast = sample(pressure); send(msgit.set(temperature, 1)); send(msgp.set(pressure, 0)); send(forecastMsg.set(weather[forecast])); // Fetch temperatures from Dallas sensors sensors.requestTemperatures(); sleep (750); // Read temperatures and send them to controller for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) { // Fetch and round temperature to one decimal float otemperature = static_cast<float>(static_cast<int>((sensors.getTempCByIndex(i)) * 10.)) / 10.; // Only send data if no error if (otemperature != -127.00 && otemperature != 85.00) { // Send in the new temperature send(msgot.setSensor(i+CHILD_ID_OTEMP).set(otemperature,1)); } } // Sleep until interrupt comes in on motion sensor but send update every minute. tripped = false; //reset tripped sleep(INTERRUPT,CHANGE, SLEEP_TIME); } float getLastPressureSamplesAverage() { float lastPressureSamplesAverage = 0; for (int i = 0; i < LAST_SAMPLES_COUNT; i++) { lastPressureSamplesAverage += lastPressureSamples[i]; } lastPressureSamplesAverage /= LAST_SAMPLES_COUNT; return lastPressureSamplesAverage; } // Algorithm found here // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf // Pressure in hPa --> forecast done by calculating kPa/h int sample(float pressure) { // Calculate the average of the last n minutes. int index = minuteCount % LAST_SAMPLES_COUNT; lastPressureSamples[index] = pressure; minuteCount++; if (minuteCount > 185) { minuteCount = 6; } if (minuteCount == 5) { pressureAvg = getLastPressureSamplesAverage(); } else if (minuteCount == 35) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change * 2; // note this is for t = 0.5hour } else { dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value. } } else if (minuteCount == 65) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) //first time initial 3 hour { dP_dt = change; //note this is for t = 1 hour } else { dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value } } else if (minuteCount == 95) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 1.5; // note this is for t = 1.5 hour } else { dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value } } else if (minuteCount == 125) { float lastPressureAvg = getLastPressureSamplesAverage(); pressureAvg2 = lastPressureAvg; // store for later use. float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2; // note this is for t = 2 hour } else { dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value } } else if (minuteCount == 155) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 2.5; // note this is for t = 2.5 hour } else { dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value } } else if (minuteCount == 185) { float lastPressureAvg = getLastPressureSamplesAverage(); float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR; if (firstRound) // first time initial 3 hour { dP_dt = change / 3; // note this is for t = 3 hour } else { dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value } pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past. firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop. } int forecast = UNKNOWN; if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval. { forecast = UNKNOWN; } else if (dP_dt < (-0.25)) { forecast = THUNDERSTORM; } else if (dP_dt > 0.25) { forecast = UNSTABLE; } else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05))) { forecast = CLOUDY; } else if ((dP_dt > 0.05) && (dP_dt < 0.25)) { forecast = SUNNY; } else if ((dP_dt >(-0.05)) && (dP_dt < 0.05)) { forecast = STABLE; } else { forecast = UNKNOWN; } // uncomment when debugging //Serial.print(F("Forecast at minute ")); //Serial.print(minuteCount); //Serial.print(F(" dP/dt = ")); //Serial.print(dP_dt); //Serial.print(F("kPa/h --> ")); //Serial.println(weather[forecast]); return forecast; }
and here are a couple of photos, front and back:
![alt text]( image url)DSC_0669 (1).jpg
![alt text]( image url)DSC_0668 (1).jpg -
RE: GatawayESP8266 - Compile error
@eiten Ran into the same error but of course the community is always at hand, ready to help! Great! I'm using MySensors 2.3.2 release version. Downgrading the ESP8266 board library to 2.7.4 as suggested by @OldSurferDude did the trick.
I'm still clinging to MySensors. So simple and inexpensive to use! All sensors and other stuff connects over three MQTT GW in three locations back to my Home Assistant.
PS: Get well soon!Regards, Gunnar
-
RE: Trying to design MySensors PCB / Fritzing
Hi!
I absolutely recommend that you invest the time needed to learn KiCad. Then you get all this stuff with clearances for free. You also get a whole library with footprints for components. KiCad will print originals for making the PCBs if you do that yourself.
You could also send the KiCad .pcb file to e.g. www.oshpark.com in the US. They charge $5 per sq. inch of 2-layer board and you get 3-boards for that price. They normally take one week to do the job and the result is excellent! -
RE: Pro Mini issues
@dbemowsk Strange! I have never made a manual reset when programming my Pro Minis.
-
RE: MySensors --> MQTT --> OpenHab 2.5
Let me offer my thoughts and recommendations:
For myself I have been using MQTT as the connection method for a number of years.
Doing that, you must have an MQTT broker as the "middle-man" to receive MQTT messages from the MySensors MQTT gateway and then relaying them to OH, which then uses the MQTT binding. Then you do not use the MySensors binding to OH at all.
The advantage is that you can have a number of sources/sensors feeding information to the MQTT broker. In my case I have three geographical sites with MySensors nodes, each with an MySensors MQTT gateway, feeding the broker. Actually at one of the sites there is also a Sonoff switch that also reports status and gets commands via MQTT. (I am using the Espurna SW on the Sonoff).
Then my OH installation subscribes to the broker via the OH MQTT binding.
To dive deeper into details, because of this geographical set-up, I am using a commercial MQTT broker, which is accessible over the internet from all three sites. If you only operate one site, then you are better off using e.g. Mosquitto inside your firewall.As far as I understand the OH MQTT binding does not offer auto-discovery unless you use the Homie naming convention. Check the OH documentation please.
For MySensors nodes I use the MySensors notation so a typical message looks like: mqttgw1/28/3/1/0/0 23.2 for say, a node-ID 28 and child-ID 3 that reports a temperature of 23.2 °C
When I started using MQTT and the 1.0 binding I made all definitions in the .items text file but when I converted to MQTT 2.0 I have made all the definitions in the PaperUI. It is either/or depending on your preferences but I think the general recommendation in the OH community is to use the PaperUI.
If you stick with text files I strongly recommend that you use Visual Studio Code and the OpenHAB extension to VS. Then you get syntax checking and nice colours to all keywords.
As far as I understand, the MySensors OH-binding uses the ethernet or serial MySensors GW. Probably the set-up is simpler in the beginning but offers less flexibility in the long run. I could never have achieved my set-up above using just a serial connection.
-
RE: RGB LED strip
@maghac I have implemented your 1.8 and I am impressed with the good structure and the performance of your code! Kudos!
-
RE: Arduino with voltage regulator
Filtering the power lines on input and output is generally not a critical issue when it comes to the value of the capacitors unless you plan to produce a large number of boards when cost of components become the issue.
If you are looking for a trouble-free operation it is better to be safe than sorry and to be conservative in the dimensioning. So 10 uF on the output is better than 2.2 since it provides more filtering of low frequency noise. 0.1 uF is better than 470 pF since it provides more filtering of high frequency noise. 10 uF on the input also filter out spikes in the input power, should there be any, so that they do not pass through the regulator. It is good practice to have both a 10 uF and a 0.1 uF capacitor on the output since they have different electrical capabilities to filter low and high frequency noise.
So in essence, the value of filtering capacitors is not that critical most of times. Too little filtering could give you issues with the radio, which is sensitive to noise on the power lines. This is why there always should be a capacitor of at least 4.7 uF close to the radio power input.
-
RE: PIR sensor firing every 20 seconds
In my experience PIR sensor are very sensitive to spikes in the power supply, especially if you run them on voltages close to the lower limit. I feed mine with a separate +8 volt supply. If you run it on the same 5 volt supply as the ESP8266 you are almost guaranteed to get false triggers. The 20 seconds is probably the time after which the PIR resets. This causes a spike on the supply which triggers the PIR again. This happened to me.
-
RE: Where do i start?
I have made the same journey starting a few years back.
I am using OpenHab www.openhab.org as the controller. First running on an RPi, now on a NUC-clone.
Two MySensors MQTT GWs. One using an NodeMCU the other an old RPi A. About a dozen of sensors based on Arduino Pro Mini, most on battery.
One piece of advise: Do not start by trying to put everything (sensor, GW (and controller)) in one node. It makes debugging much more difficult. Get yourself a couple of Arduinos (Mini or Nano) as sensor nodes. Then e.g. a Node MCU as GW and an RPi as controller. I think it makes understanding the system more easy.
Also, start with a simple sensor like temperature. Building a PIR sensor as your first project is difficult, especially if you want it to operate on batteries.
-
RE: 💬 Motion Sensor
@Patrik Söderström I think this is normal. Please check the Serial Protocol spec. under Download & API above to understand what the different elements describe. You should get this message once every two minutes if SLEEP_TIME = 120000 and you do not trigger the PIR. If triggered you should get 0;1;1;0;16;1 followed by 0;1;1;0;16;0 when the PIR resets. I built the Motion detector using the MiniPIR module above but I found that it needs at least +5V to operate reliably. Below 5V I think I remember that I got a lot of false trigs.
-
RE: Temp-Monitoring using OpenHab, MQTT, Pi 3 & Uno
@nizoo91 Hi!
I'll try to shed some light on your questions 1 and 3.Question 3. Right. If the Broker is hosted on the same RPi as OpenHab (OH), then localhost is correct.
Question 1. The question is not correct. The sequence of transmission from sensor to OH is the following:
a.) The Arduino sensor sends its data to the MySensors MQTT GW, which in your case is hosted on the RPi.
b.) The MySensors MQTT GW publishes the data to the MQTT Broker, which in your case also is hosted on the RPi. The MQTT broker acts like a hub for the MQTT messages.
c.) OH uses the MQTT-binding to subscribe to the messages that come into the MQTT Broker and does its magic.This is a very efficient set-up especially if you have, as I have, several places with sensors, each reporting via their own MySensors MQTT GW to one MQTT Broker which then OH can subscribe to.
But for learning both MySensors and OH at the same time, it will be a bit complicated.Some good sources of knowledge is www.openhab.org where you will learn everything about OH. The OH community is also very much alive. I recommend that you use that site for learning OH instead of other sources.
To learn MQTT and how this works, you can start using a tool called mqtt.fx which is available from the website with the same name. Then you can connect to your broker and watch incoming messages from the MySensors GW. You can also inject MQTT messages with that tool and make OH do things.
For a simpler set-up just install the MySensors serial GW and have that talk directly to OH. There is an OH binding available for MySensors I think but I have no experience with that.
Coming to grips with all of this is a bit of a steep learning curve but don't give up. Start piece by piece and get the different parts working and then connect them together. I have done it! Good luck!
-
RE: Mysensors mqtt gateway (noob question).
@capibara
Yes, you are getting there!
The topic prefix is just as you say defined by the #define statement.
The rest of the topic is defined as described in the API definition (Serial protocol) so:
/node-id/sensorchild-id/command/ack/type/
The content of the message is the payload.
Example: this is copied from my GW:
ib9sensors-out/21/2/1/0/4 1014 => So the sensor id is 21/ the child is 2/ this is a "set" message/ no-ack/ payload type is V_PRESSURE. The content of the message is 1014 which is just the atmospheric pressure here today.
I recommend using an MQTT client test tool like MQTT.fx It helps a lot when debugging.I am not the right guy to answer how to re-define the topic structure. I guess you will have to do some serious work on the MQTT GW software.
-
RE: Using RaspPi as Gateway + Controller AND MQTT
@robertjuric Hi!
For a number of years I was running OpenHAB with influx and grafana on an RPi and it worked very well but eventually I gave that up. A few months back I got a NUC, Intel Celeron based with SSD, $200 from China.The reason for switching HW was that sooner or later, after a year or so, the SD-card would get corrupt. I would get all sorts of mystical errors. The response time increased and the system got harder and harder to maintain. I suspect that influx data storage to the card was the main culprit. Of course you can connect an SSD and move the system to that but it all got too complex and at the end I felt that the RPi in the long run would not provide the power needed.
Now I run OH 2.3 + influx + grafana under Ubuntu 18.04 and it runs very cool. CPU-load is almost never above 1%.
In my set-up I have two geographical sites with a number of MySensors nodes and some 433 MHz switches. They connect to an MQTT GW on each site. One is a 1:st gen RPi, the other is an MCU.Since I then have two MQTT streams I use an external, commercial MQTT broker and OH connects as a client to that broker and subscribes to the various topics. I prefer this rather than setting up a VPN from the remote site, which would be an alternative to using the commercial MQTT broker.
If you only have a local set-up of course you could run your mosquitto broker on the same node as OH, influx and grafana. Personally I would still use a separate GW. I feel that this would be easier to maintain but I recognise that this brings one more node to the "closet".
-
RE: Possible problem with sketch?
Hi @Homer
The reason that the controller does not reflect the status of the relay is that you are not telling it that the status has changed.This is a snippet of how I have coded the same thing:
void receive(const MyMessage &message) { if (message.type == V_STATUS) { state = message.getBool(); // Change relay state setRelayState(RELAY_PIN, state); saveState(CHILD_ID_RELAY, state); // Store state in eeprom // Write some debug info printStateChangedDebug(CHANGE_STATE_SOURCE_RADIO, CHILD_ID_RELAY, state); } } // Set status of relay pin void setRelayState(byte relayPin, bool value) { digitalWrite(relayPin, value ? RELAY_ON : RELAY_OFF); send(msgSW.set(state), false); // acknowledge new state to controller, no ack requested }
When the message is received, I first change the relay, then I confirm the status with the send-message.
-
RE: Interrupted sleep
I had the same issue some time ago, measuring time while asleep and running on batteries. I ended up building this project: Battery operated rain gauge..
The time between reports is controlled by a CMOS 555 timer, independently from the Arduino. Needless to say I did not include any other sensors. -
RE: Node unable to find parent
@ElCheekytico
I cannot find that you set your NODE_ID in the beginning of the sensor sketch.
Since OpenHAB does not hand out node-id as far as I know (I do not use the MySensors binding in OpenHAB since I connect over mqtt) you have to set NODE_ID manually.Note: The GW does not assign node id either.
In your sensor sketch, start by adding
#define MY_NODE_ID 5
for example and see if you are able to connect.
-
What do "error-blinks" say?
Is there any documentation available about what different "error-blinks" mean in the MySensors MQTT gateway?
I just built one based on an RPi A and it works just fine. Now and then I get error blinks, different number of red blinks. They signal failure in some way but what failure? Collision, bad reception or what?
-
RE: MQTT GW on RPi A drops connection after a while
@crankycoder
Interesting!
I am using a mobile broadband connection and it seems to have some issues with drop-outs in the connection. I'll pursue this path first.
Power should not be an issue. I have a 2.5 A wall-wart supplying the Pi. -
RE: Lux sensor (BH1750) sending battery level (V)
The line
float Vcc = readVcc()/1000;
should be:
float Vcc = readVcc()/1000.;
to start with. Note the decimal point! If read Vcc() returns a float, you cannot divide by an integer.
-
RE: Node not working with existing Gateway
@neo-mod
To me, the log seems to indicate that the radio connection is not working.
If the HW is identical (with capacitor on the radio power connection) then I can see two causes:- Faulty nRF24. Try switching the radion module
- Distance between node 2 and GW too far or something blocking the radio transmission. Try moving node closer to GW.
-
RE: Beginner Problems
It looks like your sensor does not find the gateway.
What does your sensor sketch look like?
What interface do you use to OpenHab? Openhab binding?
Did you set a node-ID manually in the sketch? OH does not assign node-IDs automatically as far as I know. -
RE: Beginner Problems
@sharpy
I have no good idea why one radio worked and the other not. The PA+LNA radio requires more power but that should not be an issue on the gateway. I assume you have a good capacitor, 4.7 μF or more on the radio power connection. I normally use 22 μF since I have plenty of them.You set the node-ID manually by including:
#define NY_NODE_ID 4
or whatever number you like to use. This should be in your sketch before the
#include <MySensors.h>
Like all other #defines
Look under Configuration on this page: https://www.mysensors.org/download/sensor_api_20 -
RE: Problem with Mosquitto Topic
@mfalkvidd said in Problem with Mosquitto Topic:
MY_MQTT_PUBLISH_TOPIC_PREFIX
@exblematique
I am using three different MQTT gateways in three different geographical locations and have done so for years. Each having their own MY_MQTT_PUBLISH_TOPIC_PREFIX. It works perfectly! -
RE: MQTT GW on RPi A drops connection after a while
I did try another RPi but same result.
I have switched the 3G router to a TP-link Archer MR400 with built-in 3G modem. The 3G connection appears very stable with high signal strength. Still the MQTT MysGW drops out now and then, approx. once every two days. Connection between router and GW is ethernet cable. Since the GW is located abt. 400 km from home, I am not able to troubleshoot effectively.
So I applied brute force and set up a cron job that restarts mysgw once every 24 hours. This seems to do the trick. I am not disconnected for any longer time than that.
Strange though that I do not have to restart the RPi. If the issue is caused by the internet connection dropping out, the RPi seems to be able to recover. The GW however seems unable to recover from such a short interruption. So, something similar as @CrankyCoder has experienced.
-
RE: Trouble with the JSN SR04T
@sundeep-goel
Oh! This sounds a lot like the problems I have had for the past year. Like @zboblamont I have been pulling my hair trying to find a solution.The tank is a square profile septic tank, cross section 1 x 1 m. Access to the tank is through a manhole some 60 cm diameter.
First i tried mounting the sensor in the lid of the manhole but all the time I ended up with measurements like 20 - 30 cm, no matter what the liquid level was.
I then tried to mount a baffle around the sensor trying to limit the beam spread so that the sensor would not see the corrugated wall of the manhole. No luck!
Next idea was to increase the powerfeed to the sensor. First it was powered from one of the digital pins of the Arduino, giving some 4.x volts. So, thinking this was below specs, I built a circuit that gave the sensor proper 5 V as needed. No luck!
The final solution was to mount the sensor at the bottom end of a plastic tube, 30 mm outer dia and then feed the cable through the tube and out to the electronics. The tube is attached to the wall of the manhole using a plastic clip. Please see attached photos. Success!
So clearly my problem was caused by the sensor getting reflexes from the corrugated wall of the manhole.
-
RE: Trouble with the JSN SR04T
Yes, I take five consecutive readings 100 ms apart and calculate the median value of the readings that fall within allowed limits. Off-scale readings are discarded before calculating the median value.
It has been running for two weeks now and seems to be accurate and stable.
-
RE: Problems ethernet GW with ESP8266- NodeMcu V3.4
I have exactly the same problem with the ESP8266 MQTT GW. It compiles and loads but there is nothing on the serial output. The ESP does not appear on the WiFi either. I have run other sketches like the NTP-server and the Blink sketch with exactly the same settings for the compiler. There is no difference if the radio is connected or not. My wiring is very simple, nothing connected except the micro-USB.
The suggestion by @peripi makes no difference. The bootload message comes at 74880 speed. Shifting to 9600 or setting any other speed for that matter makes no difference.Since I have compiled and run this same sketch earlier, I suspect there have been some breaking changes in the library version 3.0.2 or possibly elsewhere.
I post my code below but I think it is identical to the reference sketches on MySensors.
/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * 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. * ******************************* * * REVISION HISTORY * Version 1.0 - Henrik Ekblad * Version 1.1 - Gunnar Blockmar 2019-05-19 Configuration for Sjövik WLAN * * DESCRIPTION * The ESP8266 MQTT gateway sends radio network (or locally attached sensors) data to your MQTT broker. * The node also listens to MY_MQTT_TOPIC_PREFIX and sends out those messages to the radio network * * LED purposes: * - To use the feature, uncomment WITH_LEDS_BLINKING in MyConfig.h * - RX (green) - blink fast on radio message recieved. In inclusion mode will blink fast only on presentation recieved * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly * - ERR (red) - fast blink on error during transmission error or recieve crc error * * See http://www.mysensors.org/build/esp8266_gateway for wiring instructions. * nRF24L01+ ESP8266 * VCC VCC * CE GPIO4 * CSN/CS GPIO15 * SCK GPIO14 * MISO GPIO12 * MOSI GPIO13 * * Not all ESP8266 modules have all pins available on their external interface. * This code has been tested on an ESP-12 module. * The ESP8266 requires a certain pin configuration to download code, and another one to run code: * - Connect REST (reset) via 10K pullup resistor to VCC, and via switch to GND ('reset switch') * - Connect GPIO15 via 10K pulldown resistor to GND * - Connect CH_PD via 10K resistor to VCC * - Connect GPIO2 via 10K resistor to VCC * - Connect GPIO0 via 10K resistor to VCC, and via switch to GND ('bootload switch') * * Inclusion mode button: * - Connect GPIO5 via switch to GND ('inclusion switch') * * Hardware SHA204 signing is currently not supported! * * Make sure to fill in your ssid and WiFi password below for ssid & pass. */ #include <EEPROM.h> #include <SPI.h> // Enable debug prints to serial monitor #define MY_DEBUG // Use a bit lower baudrate for serial prints on ESP8266 than default in MyConfig.h #define MY_BAUD_RATE 9600 // Enables and select radio type (if attached) #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 // Set this nodes subscripe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "prefix-out" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "prefix-in" // Set MQTT client id #define MY_MQTT_CLIENT_ID "sensors" // Enable these if your MQTT broker requires usenrame/password #define MY_MQTT_USER "hidden" #define MY_MQTT_PASSWORD "xyz123" // Set WIFI SSID and password #define MY_WIFI_SSID "secret" // Change this at deployment #define MY_WIFI_PASSWORD "secret" //Change this at deployment // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. #define MY_HOSTNAME "test-gateway" // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP) //#define MY_IP_ADDRESS 192,168,178,87 // If using static ip you need to define Gateway and Subnet address as well //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1 //#define MY_IP_SUBNET_ADDRESS 255,255,255,0 // MQTT broker ip address. //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 #define MY_CONTROLLER_URL_ADDRESS "xxx.cloudmqtt.com" // The MQTT broker port to to open #define MY_PORT 12345 // Flash leds on rx/tx/err does not work on ESP8266 no free pins // #define MY_LEDS_BLINKING_FEATURE // Set blinking period // #define MY_DEFAULT_LED_BLINK_PERIOD 300 // Enable inclusion mode // #define MY_INCLUSION_MODE_FEATURE // Enable Inclusion mode button on gateway // #define MY_INCLUSION_BUTTON_FEATURE // Set inclusion mode duration (in seconds) // #define MY_INCLUSION_MODE_DURATION 60 // Digital pin used for inclusion mode button // #define MY_INCLUSION_MODE_BUTTON_PIN 3 // #define MY_DEFAULT_ERR_LED_PIN 1 // Error led pin // #define MY_DEFAULT_RX_LED_PIN 9 // Receive led pin // #define MY_DEFAULT_TX_LED_PIN 0 // Transmit led pin #include <ESP8266WiFi.h> #include <MySensors.h> void setup() { } void presentation() { // Present locally attached sensors here } void loop() { // Send locally attached sensors data here }
So at the end of my wits.
-
RE: Problems ethernet GW with ESP8266- NodeMcu V3.4
I also edited according to @Yveaux 's workaround and it works!
I found however that in order to get the MQTT GW to listen to messages and forward them to the broker, I had to set wait(2000); in the void loop()
If I set wait(0) the GW started but did not listen to messages. If I set wait(100); the GW started spamming the broker with the presentation message.Again, a big thank you to everybody involved. "Now we are cooking with gas again!"