@zboblamont thank you very much.
I'll post my result after I done it.
what was the best antenna you used for your project?
Posts made by tsunami
-
RE: RFM69HW antenna
-
RE: RFM69HW antenna
@zboblamont thank you for your reply
how can I use box as a reflector?
connecting GND to the box is enough?
I'm going to design PCB but I don't know how is the schematic of the antenna connection to RFM which you have said above. do you have any schematic for this?
-
RE: RFM69HW antenna
@nagelc thank you, I need about 200m range for my project in the building.
-
RFM69HW antenna
hello
I'm going to build a gateway with RFM69HW and I want to put it in the metal box.
but in the metal box connection will lost and I should have a SMA antenna on the outside of the box. but I could't find any PCB schematic for SMA antenna connected to the rfm69(915mhz)
I have some questions...
1.Should I connect GND pin to the SMA plug pins?
2. does 915Mhz SMA Rubber antenna will increase the range of the RFM69HW?
3.anybody know how much is the range of this board?and any idea for designing RFM69HW shield with SMA connector?
thanks in advanced -
RE: having trouble with water flow sensor + relay + moisture
@mfalkvidd I've changed CHILD_ID for nodes but nothing changed and moisture data show up in DHT22's humidity!
-
having trouble with water flow sensor + relay + moisture
Hi, I've build my own node with mqtt to send waterflow sensor and DHT22 and moisture data to Domoticz and have one Relay to control. but both relay and waterflow sketches has receive function and when I write both of them in one function, relay doesn't show up in domoticz devices or hardware(child node);
here is my code:#include <DHT.h> #include <SPI.h> #define DHT_DATA_PIN 6 #define SENSOR_TEMP_OFFSET 0 static const uint8_t FORCE_UPDATE_N_READS = 10; static const uint64_t UPDATE_INTERVAL = 5000; #define MY_RADIO_NRF24 #define MY_RF24_PA_LEVEL RF24_PA_MAX #define MY_REPEATER_FEATURE #define MY_NODE_ID 1 #include <MySensors.h> #define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #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_MOISTURE 2 #define CHILD_ID_HUM 3 #define CHILD_ID_TEMP 4 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgMoisture(CHILD_ID_MOISTURE, V_HUM); MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); DHT dht; static int sensorValue; int soilPin = A0; int soilPower = 5; #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 450000 // Nummber of blinks per m3 of your meter (One rotation/liter) #define SLEEP_MODE false // flowvalue can only be reported when sleep mode is false. #define MAX_FLOW 30 // Max flow (l/min) value to report. This filters outliers. #define CHILD_ID_WATER 1 uint32_t SEND_FREQUENCY = 5000; // Minimum time between send (in milliseconds). We don't want to spam the gateway. MyMessage flowMsg(CHILD_ID_WATER,V_FLOW); MyMessage volumeMsg(CHILD_ID_WATER,V_VOLUME); MyMessage lastCounterMsg(CHILD_ID_WATER,V_VAR1); double ppl = ((double)PULSE_FACTOR)/1000; // Pulses per liter volatile uint32_t pulseCount = 0; volatile uint32_t lastBlink = 0; volatile double flow = 0; bool pcReceived = false; uint32_t oldPulseCount = 0; uint32_t newBlink = 0; double oldflow = 0; double volume =0; double oldvolume =0; uint32_t lastSend =0; uint32_t lastPulse =0; void before() { for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void presentation() { sendSketchInfo("Smart Irrigation System", "1.0"); present(CHILD_ID_MOISTURE, S_MOISTURE); present(CHILD_ID_WATER, S_WATER); present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); metric = getControllerConfig().isMetric; for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { present(sensor, S_BINARY); } } void setup() { pinMode(soilPower, OUTPUT);//Set D6 as an OUTPUT // initialize our digital pins internal pullup resistor so one pulse switches from high to low (less distortion) pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP); pulseCount = oldPulseCount = 0; // Fetch last known pulse count value from gw request(CHILD_ID_WATER, V_VAR1); lastSend = lastPulse = millis(); attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING); dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); } void loop() { // Force reading sensor, so it works also after sleep() dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } // Sleep for a while to save energy sleep(UPDATE_INTERVAL); //...................................................... uint32_t currentTime = millis(); // Only send values at a maximum frequency or woken up from sleep if (SLEEP_MODE || (currentTime - lastSend > SEND_FREQUENCY)) { lastSend=currentTime; if (!pcReceived) { //Last Pulsecount not yet received from controller, request it again request(CHILD_ID_WATER, V_VAR1); return; } if (!SLEEP_MODE && flow != oldflow) { oldflow = flow; Serial.print("l/min:"); Serial.println(flow); // Check that we dont get unresonable large flow value. // could hapen when long wraps or false interrupt triggered if (flow<((uint32_t)MAX_FLOW)) { send(flowMsg.set(flow, 2)); // Send flow value to gw } } // No Pulse count received in 2min if(currentTime - lastPulse > 120000) { flow = 0; } // Pulse count has changed if ((pulseCount != oldPulseCount)||(!SLEEP_MODE)) { oldPulseCount = pulseCount; Serial.print("pulsecount:"); Serial.println(pulseCount); send(lastCounterMsg.set(pulseCount)); // Send pulsecount value to gw in VAR1 double volume = ((double)pulseCount/((double)PULSE_FACTOR)); if ((volume != oldvolume)||(!SLEEP_MODE)) { oldvolume = volume; Serial.print("volume:"); Serial.println(volume, 3); send(volumeMsg.set(volume, 3)); // Send volume value to gw } } } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } soilmoisture(); } void soilmoisture() { digitalWrite(soilPower, HIGH); delay(10);//wait 10 milliseconds sensorValue = analogRead(soilPin); digitalWrite(soilPower, LOW); sensorValue = map(sensorValue, 0, 680, 0, 100); send(msgMoisture.set(sensorValue)); sleep(SEND_FREQUENCY); } void receive(const MyMessage &message) { if (message.type==V_VAR1) { uint32_t gwPulseCount=message.getULong(); pulseCount += gwPulseCount; flow=oldflow=0; Serial.print("Received last pulse count from gw:"); Serial.println(pulseCount); pcReceived = true; } if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); } } void onPulse() { if (!SLEEP_MODE) { uint32_t newBlink = micros(); uint32_t interval = newBlink-lastBlink; if (interval!=0) { lastPulse = millis(); if (interval<500000L) { // Sometimes we get interrupt on RISING, 500000 = 0.5sek debounce ( max 120 l/min) return; } flow = (60000000.0 /interval) / ppl; } lastBlink = newBlink; } pulseCount++; }
anyone can help me?
and any suggestion to clean up my code?
thanks in advanced. -
RE: esp8266 gateway doesn't connect to mqtt broker
@mfalkvidd said in esp8266 gateway doesn't connect to mqtt broker:
https://forum.mysensors.org/topic/5618/domoticz-now-supports-the-mysensors-mqtt-gateway/ might be useful
thank you I've done it and works great. but I found it if node is offline and I put switch on or off in controller it works but when node get connect to the controller it doesn't update switch state. how to fix it?
-
RE: esp8266 gateway doesn't connect to mqtt broker
@mfalkvidd said in esp8266 gateway doesn't connect to mqtt broker:
@tsunami see if removing
#define MY_PORT 11262
helps. I think this define is only meant to be used when not using MY_CONTROLLER_URL_ADDRESS (but I am not entirely sure).If that doesn't help, take a look at https://github.com/mysensors/MySensors/issues/926
It seems like the ESP8266 gateway will be unable to use DNS when using static IP configuration. In my experimental branch I have added DNS support, but it is not reliable and needs more work. You could try to use an IP address instead of m21.cloudmqtt.com - not sure if it helps but it could be worth trying.thanks alot everything works good now and gatewat has connected to the mqtt broker. but i can't connect it to the domiticz. domoticz topics are: domoticz/in/mymqtt
but for gateway is different and i can't change for domoticz. -
esp8266 gateway doesn't connect to mqtt broker
Hi, I'm using ESP8266 mqtt client gateway to connect to my controller and I use cloud mqtt service. controller has connected to the broker but esp8266 doesn't connect. even it doesn't connect to the wifi and it was a access point and I've followed a topic to add a code for turn off access point. this is my code for gateway:
#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_NRF24 #define MY_GATEWAY_MQTT_CLIENT #define MY_GATEWAY_ESP8266 // Set this node's subscribe and publish topic prefix #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" // Set MQTT client id #define MY_MQTT_CLIENT_ID "mysensors-1" // Enable these if your MQTT broker requires username/password #define MY_MQTT_USER "***********" #define MY_MQTT_PASSWORD "**************" // Set WIFI SSID and password #define MY_ESP8266_SSID "*****************" #define MY_ESP8266_PASSWORD "******************" // Set the hostname for the WiFi Client. This is the hostname // it will pass to the DHCP server if not static. // #define MY_ESP8266_HOSTNAME "mqtt-sensor-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 can define Gateway and Subnet address as well #define MY_IP_GATEWAY_ADDRESS 192,168,1,1 #define MY_IP_SUBNET_ADDRESS 255,255,255,0 //MQTT broker if using URL instead of ip address. #define MY_CONTROLLER_URL_ADDRESS "m21.cloudmqtt.com" // The MQTT broker port to to open #define MY_PORT 11262 #include <ESP8266WiFi.h> #include <MySensors.h> void setup() { // Setup locally attached sensors } void presentation() { // Present locally attached sensors here } void loop() { // Send locally attached sensors data here }```
and I get this in serial:
scandone state: 0 -> 2 (b0) state: 2 -> 3 (0) state: 3 -> 5 (10) add 0 aid 4 cnt 271 TSM:FAIL:DIS 289 TSF:TDI:TSL connected with Shatel, channel 1 dhcp client start... ip:192.168.1.6,mask:255.255.255.0,gw:192.168.1.1 pm open,type:2 0 10306 TSM:FAIL:RE-INIT 10330 TSM:INIT 10351 !TSM:INIT:TSP FAIL 10377 TSM:FAIL:CNT=2 10399 TSM:FAIL:DIS 10419 TSF:TDI:TSL
anyone knows how to fix it?
-
Help in data send to Domoticz
Hi
I'm using arduino UNO gateway + mysensors + Domoticz controller to send and receive data like "DHT", "soil moisture" and "relay state"
I got problem about reading temp and humidity; both shows in one block and the humidity doesn't update anymore. how can I set them to different blocks?
and my second problem is about soil moisture sensor, when I want to add "event" to automating relay by soil moisture data, I receive "nil value" error for event and something about global variable.
this is my code please anyone could help me I'll be grateful.
thanks in advance.#define MY_DEFAULT_LED_BLINK_PERIOD 500 #define MY_WITH_LEDS_BLINKING_INVERSE #define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin #define MY_DEFAULT_TX_LED_PIN 7 // the PCB, on board LED #include <MySensors.h> #include <SPI.h> #include <DHT.h> DHT dht; #define DHTTYPE DHT22 #define DHT_DATA_PIN 3 #define SENSOR_TEMP_OFFSET 0 const int buzzer = 5; static const uint8_t FORCE_UPDATE_N_READS = 10; #define MY_RADIO_NRF24 #define MY_RF24_PA_LEVEL RF24_PA_HIGH #define MY_REPEATER_FEATURE #define RELAY_PIN 4 // Arduino Digital I/O pin number for first relay (second on pin+1 etc) #define NUMBER_OF_RELAYS 1 // Total number of attached relays #define RELAY_ON 0 // GPIO value to write to turn on attached relay #define RELAY_OFF 1 // GPIO value to write to turn off attached relay #define CHILD_ID_SOIL 3 MyMessage msg(CHILD_ID_SOIL, V_LEVEL); uint32_t SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds) int sensorValue; int val; int soilPin = A0; int soilPower = 6; #define CHILD_ID_HUM 1 #define CHILD_ID_TEMP 2 float lastTemp; float lastHum; uint8_t nNoUpdatesTemp; uint8_t nNoUpdatesHum; bool metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); static const uint64_t UPDATE_INTERVAL = 5000; void before() { for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Then set relay pins in output mode pinMode(pin, OUTPUT); // Set relay to last known state (using eeprom storage) digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF); } } void setup() { pinMode(buzzer, OUTPUT); dht.setup(DHT_DATA_PIN); // set data pin of DHT sensor if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) { Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!"); } // Sleep for the time of the minimum sampling period to give the sensor time to power up // (otherwise, timeout errors might occure for the first reading) sleep(dht.getMinimumSamplingPeriod()); pinMode(soilPower, OUTPUT);//Set D6 as an OUTPUT digitalWrite(soilPower, LOW); } void presentation() { // Send the sketch version information to the gateway and Controller sendSketchInfo("Relay", "1.0"); for (int sensor=1, pin=RELAY_PIN; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) { // Register all sensors to gw (they will be created as child devices) present(sensor, S_BINARY); sendSketchInfo("Humidity and Temperature", "1.1"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_HUM, S_HUM); present(CHILD_ID_TEMP, S_TEMP); sendSketchInfo("Soil Moisture Sensor", "1.0"); present(CHILD_ID_SOIL, S_MOISTURE); metric = getControllerConfig().isMetric; } } void loop() { dht.readSensor(true); // Get temperature from DHT library float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT!"); } else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) { // Only send temperature if it changed since the last measurement or if we didn't send an update for n times lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } // Reset no updates counter nNoUpdatesTemp = 0; temperature += SENSOR_TEMP_OFFSET; send(msgTemp.set(temperature, 1)); #ifdef MY_DEBUG Serial.print("T: "); Serial.println(temperature); #endif } else { // Increase no update counter if the temperature stayed the same nNoUpdatesTemp++; } // Get humidity from DHT library float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) { // Only send humidity if it changed since the last measurement or if we didn't send an update for n times lastHum = humidity; // Reset no updates counter nNoUpdatesHum = 0; send(msgHum.set(humidity, 1)); #ifdef MY_DEBUG Serial.print("H: "); Serial.println(humidity); #endif } else { // Increase no update counter if the humidity stayed the same nNoUpdatesHum++; } sensorValue = readSoil(); send(msg.set(sensorValue)); // Sleep for a while to save energy sleep(UPDATE_INTERVAL); } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_STATUS) { // Change relay state digitalWrite(message.sensor-1+RELAY_PIN, message.getBool()?RELAY_ON:RELAY_OFF); // Store state in eeprom saveState(message.sensor, message.getBool()); // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(message.sensor); Serial.print(", New status: "); Serial.println(message.getBool()); tone(buzzer, 850); // Send 1KHz sound signal... delay(500); // ...for 1 sec noTone(buzzer); // Stop sound... delay(500); } } int readSoil() { digitalWrite(soilPower, HIGH); delay(10);//wait 10 milliseconds val = analogRead(soilPin); digitalWrite(soilPower, LOW); return val;//send current moisture value }