Today the new rs485 shield arrived, i will solder it up over the weekend and start testing early next week:)
Posts made by skatun
-
RE: RS485/RS232/Serial transport class for mysensors.org
-
RE: Power Measurements
i came across this one: https://github.com/FriedCircuits/ADE7753/tree/master/ADE7753_Breakout_v.2
I want it in this form
or this one, but it seems to output serial data, how many software serial can you have on one arduino?
https://www.aliexpress.com/item/Mini-Multifuncion-power-energy-amp-voltage-monitor-meter-communication-module-with-CT-coil-AC-80-260V/32512169668.html?spm=2114.01010208.3.156.Hh7LxY&ws_ab_test=searchweb0_0,searchweb201602_1_116_10065_117_10068_114_115_113_10000009_10084_10083_10080_10082_10081_10060_10061_10062_10056_10055_10054_10059_10099_10078_10079_427_10103_10073_10102_10096_10052_10050_10051-10050_114,searchweb201603_9,afswitch_3&btsid=810667df-39e8-4801-a123-f3cd7ca3456a -
RE: Power Measurements
@Talat-Keleş I am not going to use 230V to power the arduino.
The point is to get power you need P=U*I and for accuracy U is not 220V but varies quite a bit(210-230 typ), hence you need to measure it.
So for
current: 20A +-0.01A
voltage: 220+-0.1Vwe will get 20/1024 *220 = 5W resolution. In addition we need to add accuracy of sensors, so lets say 7W, so then if we pull 300W, we have only 300W+-23%..
So maybe we need to add an adc(10bit) or skip mesuring peaks(10A sensor?)
I have 20 circuit breakers so I can easily measure how much: heating is using,water heater, oven top etc...
-
Power Measurements
Hi everyone,
I would like to measure my electric power usage in my flat. In my fusebox I have several fuses like this one,
Does other have same kind of fuses?
So reading on the forum here and other places, to achieve some kind of realistic result you need measure both current and voltage. So my idea is to make a small pcb with two tabs that fits in the fuse(put wires and pcb int he screw terminals on the fuse) in order to measure voltage, then for one of the wire it goes through one of this:
As output from the pcb it will then be 2 analog signal between 0-5v and it needs 5v and gnd so the interface will be some kind of 4 pin connector(rj11 or screw terminals).
So I was wondering if others might have interest of such a sensor, then I would also like input of which sensor to use(I guess 20 A sensor such as TA12-100 for current) but what to use for voltage sensing, just resistors?
I hope such a pcb fully assembled would come out below 10usd.
Then lets say you have 6 fuses you wire up 6 of these pcb to one arduino nano node, which then transmit both current and voltage to the gatway.
-
RE: rs485 on nano
@wimd include debug and remove inclusion from the sketches and it should be ok. I have ordered new rs485 shield, i expect that to be the issue..
-
RE: rs485 on nano
Implemented fixed node ID without success, I think maybe the rs485 adapter on gateway is broken, will test more tomorrow
-
RE: rs485 on nano
@pjr @consul58 Have been away the last 5 days, will update the thread with the result tomorrow. Can anyone lighten me up on benefit of having inclusion button, and what inclusion time should be set to?
-
RE: rs485 on nano
@dbemowsk so i added the usb device, it produces gibberish:
~þx
different baud-rates, gibberish changes.....
gibberish from the node, but nothing from gateway, I also changed gateway to uno as a test without success, here is the code on gateway which i commented out:
// Flash leds on rx/tx/err //#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 4 // Error led pin //#define MY_DEFAULT_RX_LED_PIN 5 // Receive led pin //#define MY_DEFAULT_TX_LED_PIN 6 // the PCB, on board LED
-
RE: rs485 on nano
@dbemowsk What do you mean by + to + and - to - between nodes.? Isnt that just to power the max 485 chip?
I do have a usb dongle like u mentioned laying around somewhere, so I can just add that as a 3rd rs485 node, and use arduino serial monitor for it?
on the gateway i commented all the led and inclusion code, this doesnt effect the rs485 right?
My setup is shown below:
@m26872 I have now enabled debug mode, see output below
-
rs485 on nano
hi,
I haved hooked up a mega as my serial to rs485 gateway, it shows nicely up in my myscontroller as node0-gateway, to this I have connected a rs485 shield(same as here: https://www.mysensors.org/build/rs485)
so i connected DE and RE on shield to digital pin 2
on gateway i connected DI to 46 and R0 to 48 similiar my node which is nano is connected with DI to 9 and R0 to 8. They have not vcc or GND in common.I downloaded the gateway and motion sensor example from link above, but the motion sensor node does not show up, did I wire something wrong?
-
RE: Serial gateway, which example to follow??
@tekka Thats correct, i am only running locally attached sensor:) I was luckily enough to run sth like 35 cables to my gateway, I might add radio in the future to reach down to my basement.
-
RE: Serial gateway, which example to follow??
@tekka Thanks for the feedback, does that implies if I download the dev branch from git now it should be fixed?
here is the output from my serial monitor when i enabled logging:
0;255;3;0;9;Starting gateway (R-NGA-, 2.0.0-beta) 0;255;3;0;14;Gateway startup complete. 0;2;2;0;24; 0;255;3;0;9;No registration required 0;255;3;0;9;Init complete, id=0, parent=0, distance=0, registration=1 0;2;2;0;24;
I am trying to get my RGB lights to work:
#define CHILD_ID_RGB_START 30 #define NUM_LEDS_STRIPS 5 void presentation() { // Present locally attached sensors //RGB 0,30,1,0,40,ff0000\n sendSketchInfo("RGB Led", "1.2"); Serial.println("Lets present some RGB"); for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) { Serial.print("RGB ID: "); Serial.println(CHILD_ID_RGB); present(CHILD_ID_RGB, S_RGB_LIGHT); }
How can I add logging to Serial monitor to gateway, because
Serial.println("Lets present some RGB");
does not produce any output?shouldn't this line registered my lights as sensors in MYSController?
present(CHILD_ID_RGB, S_RGB_LIGHT);
So I am afraid there is something wrong with my for loop, even though i can not spot the mistake.
-
RE: Serial gateway, which example to follow??
@hek
I am making great progress on my gateway:) I am almost done wiring everything and software is coming along. So my sensors sends out data nicely to the controller, however I can not receive commands, which is essentials for my RGB led strips.I am trying to send this from the Serial Monitor in arduino: 0,30,1,0,40,ff0000\n
However the received method never gets called, what am I missing?
// Enable debug prints to serial monitor //#define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL #include <SoftwareSerial.h> #include <SPI.h> #include <MySensors.h> #include <ChainableLED.h> SoftwareSerial mySerial(10, 11); // RX, TX MyMessage msg1(1, V_LIGHT); //RGB int NUM_LEDS = 34; ChainableLED leds(5, 6, NUM_LEDS); // CLK, DATA, LEDS //PowerMeter #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. #define CHILD_ID_POWER 2 // Id of the sensor child #define CHILD_ID_RGB_START 30 #define NUM_LEDS_STRIPS 5 int counter[NUM_LEDS_STRIPS]; int current[NUM_LEDS_STRIPS][3]; int step[NUM_LEDS_STRIPS][3]; unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. double ppwh = ((double)PULSE_FACTOR) / 1000; // Pulses per watt hour boolean pcReceived = false; volatile unsigned long pulseCount = 0; volatile unsigned long lastBlink = 0; volatile unsigned long watt = 0; unsigned long oldPulseCount = 0; unsigned long oldWatt = 0; double oldKwh; unsigned long lastSend; MyMessage wattMsg(CHILD_ID_POWER, V_WATT); MyMessage kwhMsg(CHILD_ID_POWER, V_KWH); MyMessage pcMsg(CHILD_ID_POWER, V_VAR1); void setup() { //Set up all our software serial ports... mySerial.begin(9600); // Setup locally attached sensors //RGB leds.init(); for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) { counter[CHILD_ID_RGB] = 0; current[CHILD_ID_RGB][0] = 0; current[CHILD_ID_RGB][1] = 0; current[CHILD_ID_RGB][2] = 0; step[CHILD_ID_RGB][0] = 0; step[CHILD_ID_RGB][1] = 0; step[CHILD_ID_RGB][2] = 0; leds.setColorRGB(CHILD_ID_RGB, current[CHILD_ID_RGB][0], current[CHILD_ID_RGB][1], current[CHILD_ID_RGB][2]); // Turn of on startup } // Power Meter // Fetch last known pulse count value from gw request(CHILD_ID_POWER, V_VAR1); // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output // If no pullup is used, the reported usage will be too high because of the floating pin pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING); lastSend = millis(); } void presentation() { // Present locally attached sensors //RGB 0,30,1,0,40,ff0000\n sendSketchInfo("RGB Led", "1.2"); for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) { present(CHILD_ID_RGB, S_RGB_LIGHT); } //RELAY sendSketchInfo("Relay & Button", "1.0"); // Register all sensors to gw (they will be created as child devices) present(1, S_LIGHT); //POWER METER // Send the sketch version information to the gateway and Controller sendSketchInfo("Energy Meter", "1.0"); // Register this device as power sensor present(CHILD_ID_POWER, S_POWER); } void loop() { // Send locally attached sensor data here //send(msg1.set(true), true); // Send new state and request ack back if (mySerial.available()) { Serial.write(mySerial.read()); } //RGB for (byte CHILD_ID_RGB = CHILD_ID_RGB_START; CHILD_ID_RGB < NUM_LEDS_STRIPS; CHILD_ID_RGB++) { if (counter[CHILD_ID_RGB] >= 0) { counter[CHILD_ID_RGB]--; int i = 1020 - counter[CHILD_ID_RGB]; current[CHILD_ID_RGB][0] = calculateVal(step[CHILD_ID_RGB][0], current[CHILD_ID_RGB][0], i); current[CHILD_ID_RGB][1] = calculateVal(step[CHILD_ID_RGB][1], current[CHILD_ID_RGB][1], i); current[CHILD_ID_RGB][2] = calculateVal(step[CHILD_ID_RGB][2], current[CHILD_ID_RGB][2], i); leds.setColorRGB(CHILD_ID_RGB, current[CHILD_ID_RGB][0], current[CHILD_ID_RGB][1], current[CHILD_ID_RGB][2]); } } //POWER unsigned long now = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { // New watt value has been calculated if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt < ((unsigned long)MAX_WATT)) { send(wattMsg.set(watt)); // Send watt value to gw } Serial.print("Watt:"); Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { send(pcMsg.set(pulseCount)); // Send pulse count value to gw Serial.print("PulseCount:"); Serial.println(pulseCount); double kwh = ((double)pulseCount / ((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; Serial.print("KWh:"); Serial.println(kwh); } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID_POWER, V_VAR1); Serial.println("requesting a new value"); lastSend = now; } } //PowerMeter void onPulse() { unsigned long newBlink = micros(); unsigned long interval = newBlink - lastBlink; if (interval < 10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 / interval) / ppwh; lastBlink = newBlink; pulseCount++; } //RGB void setColor(byte led, int R, int G, int B) { step[led][0] = calculateStep(current[led][0], R); step[led][1] = calculateStep(current[led][1], G); step[led][2] = calculateStep(current[led][2], B); counter[led] = 255; } int calculateStep(int prevValue, int endValue) { int step = endValue - prevValue; // What's the overall gap? if (step) { // If its non-zero, step = 255 / step; // divide by 1020 } return step; } int calculateVal(int step, int val, int i) { if ((step) && i % step == 0) { // If step is non-zero and its time to change a value, if (step > 0) { // increment the value if step is positive... val += 1; } else if (step < 0) { // ...or decrement it if step is negative val -= 1; } } // Defensive driving: make sure val stays in the range 0-255 if (val > 255) { val = 255; } else if (val < 0) { val = 0; } return val; } void receive(const MyMessage & msg) { Serial.println("Hello"); //send(msg1.set(true), true); if (msg.type == V_RGB) { String hexstring = msg.getString(); long number = (long) strtol( &hexstring[0], NULL, 16); int colorR = number >> 16; int colorG = number >> 8 & 0xFF; int colorB = number & 0xFF; // Write some debug info Serial.print("Incoming change for sensor:"); Serial.print(msg.sensor); Serial.print(", Red: "); Serial.print(colorR); Serial.print(", Green: "); Serial.print(colorG); Serial.print(", Blue: "); Serial.print(colorB); Serial.print(", New status: "); Serial.println(msg.getString()); setColor(msg.sensor, colorR, colorG, colorB); //leds.setColorRGB(message.sensor, colorR, colorG, colorB); } //POWER if (msg.type == V_VAR1) { pulseCount = oldPulseCount = msg.getLong(); Serial.print("Received last pulse count from gw:"); Serial.println(pulseCount); pcReceived = true; } //Locally attached sensor...... if (msg.destination == 0) { } //We forward our message on software serial else if (msg.destination == 10) { Serial.println("halla 3"); //mySerial.write(msg.getStream()); //is this the complete message?? } // send it out on the radio modem, to be implemented later else { } }
-
RE: Serial gateway, which example to follow??
Quote:"means of the wired protocol"
I was so fortunate that I could connect most of my nodes and sensors wired, more reliable, no need to change battery so I tried todo so with most of my nodes and sensors.Quote : "Then if you want to combine this with radio communication you need a different gateway"
Why do I need two gateways, why cant one gateway handle both wired and radio? For now I don't need the radio, just locally and wired connectionQuote:" Each of these nodes needs a different node number."
Yupp thats why I try to give them static node numbers: So the one on balcony gets ID 11 the one in the bar is 13 and so on. (my idea was to group ID numbers, 0 locally sensor, 10-19 software serial, >20 radio nodes, >50 wifi nodes ,>70 rs485 nodes)The benefit of using MySensor is that the Openhab has a binding for it, I can use the example codes for my nodes(like the relay with button sketch) and I need some format of the string sended/received from the controller to my nodes anyway, so why not use the mysensor format?
so My orignally Idea was to use the serial event:
void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inputPos < MAX_RECEIVE_LENGTH - 1 && !commandComplete) { if (inChar == '\n') { inputString[inputPos] = 0; commandComplete = true; } else { // add it to the inputString: inputString[inputPos] = inChar; inputPos++; } } else { // Incoming message too long. Throw away inputPos = 0; } } }
and then use the Message class to split the input buffer the string based
","
like in vba I would just usearrayMy = split(inputBuffer,",")
Then If ID=11 forward the whole thing to software serial to the balcony, then the code on that node would be exactly the same as if the message came over the radio link.
That was my orginally idea, but then @hek suggested that I should rather use the receive method since this grab the buffer from serial somehow.
I am open to all solutions:) I just have limited space on some of my nodes which makes it hard to implement a radio link on them as well as an rs485 shield. (even using nano is hard)
-
RE: Serial gateway, which example to follow??
@AWI
Basically I have my Gateway(Mega, might swap to Due, higher resolution ADC), on my gateway I have:
1 radio modem connected,
7 Arduino nano which are soldered to tx/rx(I might need to resolder those?),
12 motion sensors,
1 pulsePowerMeter,
6 ledstrips
1 IR generator(simulate my tv /stereo,etc remote)So if my controller Openhab:
sends or receive CHildID = 0 then send/receive data to locally attached sensor
sends or receive CHildID = 10-16 then send/receive data on software serial to the 7 arduino nano(Basically relay sensor nodes)
sends or receive CHildID = 20-31 then send/receive data on radio to my radio nodes(temperature mainly)My problem is that I can not figure out how to set up software serial with my sensor.
If msg.destination =16 sendTo software Serial on pin 34
Below is a picture of my Gateway setup:
-
RE: Serial gateway, which example to follow??
Its not something in the transport class I need to change right?
-
RE: RS485/RS232/Serial transport class for mysensors.org
@LeoDesigner
Hi, I am trying to do almost the same, but I would like to use softwareSerial instead of altsoft. The reason why I would do this is that i can barely fit the arduino nano inside my case, and an additional rs485 module would not fit and that I have 8 nodes connected on the softwareserial . I have tested software serial on arduino and it seems to work fine up to 15meters, I also adjusted the baudrate to 9600 since my node does not send out/receive large amount of data. I read that you did some work on software serial and were wondering if you could take a look at this thread. -
RE: Serial gateway, which example to follow??
@hek
So finally I got home to grab my arduino so I can do some hardware testing and not just software!It seems like the receive method is not running on the gateway, I have read through everything on the library api three times now, but I still can not figure out how the receive method are working. It runs inside the main loop, hence you can not use any sleep routine as far as I understood.
image url)What can I do to get the receive method to run?
-
RE: [SOLVED] Gateway without radio not working on current development branch
@chrlyra
If I am not completely wrong, this fix is only to 2.0 -
RE: [SOLVED] Gateway without radio not working on current development branch
On windows 7 it ask me to replace files with new one, when I click yes, everything works fine. The main issue is to detect when new files are available and then do the update. These days I keep downloading the development branch around once a month to make sure I am not working on to old versions.
-
RE: Serial gateway, which example to follow??
@hek
Now it compiles:) Thanks. So 2 questions for you:
1:The receieve event is triggered when a whole string with \n is received on the serial line?
2: How to get the whole string sent from controller?msg.getString()
ormsg.getStream()
(Trying to understand the MyMessage.h file...)Updated code below
// Enable debug prints to serial monitor //#define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL #include <SoftwareSerial.h> #include <SPI.h> #include <MySensors.h> SoftwareSerial mySerial(10, 11); // RX, TX void setup() { //Set up all our software serial ports... mySerial.begin(9600); // Setup locally attached sensors } void presentation() { // Present locally attached sensors //how to do this??? } void loop() { // Send locally attached sensor data here if (mySerial.available()) { Serial.write(mySerial.read()); } } void receive(const MyMessage &msg) { //Locally attached sensor...... if (msg.destination == 0) { } //We forward our message on software serial else if (msg.destination == 10) { //mySerial.write(msg); //is this the complete message?? } // send it out on the radio modem, to be implemented later else { } }
-
RE: Serial gateway, which example to follow??
@hek
Thanks, I have downloaded today the 2.0 version from github
This however gives me this error code:In file included from C:\Users\kim\Documents\Arduino\openhab\openhab.ino:4:0: C:\Users\kim\Documents\Arduino\libraries\MySensors/MySensors.h:287:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^
Which I thought was patched now..
I also tried to implement the receive code as you suggested, see code below in version 2.0 style and not 1.5 style as the webpage suggest. My gateway currently are pretty simply, if it receieve node id= 10 send it off on software serial, i.e send the whole buffer to that node. (Eventually I will have 7 software serial nodes..id =10..16 and 24 locally attached sensors, as well as a few radio nodes)
#include <SoftwareSerial.h> #include <SPI.h> #include <MyConfig.h> #include <MySensors.h> // Enable debug prints to serial monitor //#define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL SoftwareSerial mySerial(10, 11); // RX, TX void setup() { //Set up all our software serial ports... mySerial.begin(9600); // Setup locally attached sensors } void presentation() { // Present locally attached sensors } void loop() { // Send locally attached sensor data here gw.process(); //Just forward data received on software serial to the controller if (mySerial.available()) { Serial.write(mySerial.read()); } } void receive(const MyMessage &msg) { //Locally attached sensor...... if (msg.destination = 0) { } //We forward our message on software serial else if (msg.destination = 10) { mySerial.write(msg); //is this the complete message?? } // send it out on the radio modem, to be implemented later else { } }
-
RE: Serial gateway, which example to follow??
@hek
Thanks, so this link is not valid?so how can I use the receive method to obtain the nodeID?
nodeID = receive().destination
-
RE: [SOLVED] Gateway without radio not working on current development branch
Is there a smarter way to upgrade the development version on windows instead of download zip file-> extract it-> replace files? Also how can I find out if its outdated or not? I am going to download the new version now to see if the patch works and hence I were wondering the best way to do so:)
-
RE: Serial gateway, which example to follow??
@skatun said:
MyMessage msg = new MyMessage(); // fails here.....
msg.set(commandBuffer);
It is basically this piece of the code I have problems with:)
-
RE: [SOLVED] Gateway without radio not working on current development branch
Fyi, I had same problem with serial gateway. I guess that is fixed now aswell as the ethernet gateway?
-
Serial gateway, which example to follow??
Hi all, I am pretty new to Mysensor, however I have used some sensor code successfully.
My setup is a RPI b+ running openhab connected to my gateway with usb cable which is an arduino due.
So the plan is to use the openhab binding to connect tothe gateway. So my idea was that locally attached sensor will be assigned node id 0-9, softwareserial nodes 10-19 and rf everything higher.
So I started reading up on the serial gateway, the one that comes in the sketch folder of the development branch, on the mysensor webpage, some on rpi. So I am unsure which one to use.. The one in the sketch folder, I dont know how to decode income serial message and send it off on the software serial, also it fails to compile when you disable RF(like if you only have locally attached sensors or software serial nodes)
I also did some reading up on rs422 and software serial.
So I have made a sketch that almost compiles, I only have an issue with using the MyMessage library to split the incoming string and were wondering if someone could help me out on how to use it so that i can redirect incoming nodeID 10 to software serial.
#include <SoftwareSerial.h> #include <SPI.h> #include <MyConfig.h> #include <MySensors.h> // Enable debug prints to serial monitor //#define MY_DEBUG /* * Un comment the lines below whenever we want to use a radio modem.. */ // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 // // Enable serial gateway #define MY_GATEWAY_SERIAL SoftwareSerial mySerial(10, 11); // RX, TX //Some constant that holds the things received on serial line #define MAX_RECEIVE_LENGTH 100 // Max buffersize needed for messages coming from controller #define MAX_SEND_LENGTH 120 // Max buffersize needed for messages destined for controller char inputString[MAX_RECEIVE_LENGTH] = ""; // A string to hold incoming commands from serial/ethernet interface int inputPos = 0; boolean commandComplete = false; // whether the string is complete //Switch Bar "Bar" <drink> (gBar) {mysensors="1;2;V_LIGHT"} void parseAndSend(char *commandBuffer) { MyMessage msg = new MyMessage(); // fails here..... msg.set(commandBuffer); //Locally attached sensor...... if (msg.destination = 0) { } //We forward our message on software serial else if (msg.destination = 10) { mySerial.write(commandBuffer); } // send it out on the radio modem, to be implemented later else { } } void setup() { // Send startup log message on serial //serial(PSTR("0;0;%d;0;%d;Gateway startup complete.\n"), C_INTERNAL, I_GATEWAY_READY); //Set up all our software serial ports... mySerial.begin(9600); // Setup locally attached sensors } void presentation() { // Present locally attached sensors //how to do this??? } void loop() { // Send locally attached sensor data here //gw.process(); if (commandComplete) { // A command wass issued from serial interface // We will now try to send it to the actuator parseAndSend(inputString); commandComplete = false; inputPos = 0; } if (mySerial.available()) Serial.write(mySerial.read()); } void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inputPos < MAX_RECEIVE_LENGTH - 1 && !commandComplete) { if (inChar == '\n') { inputString[inputPos] = 0; commandComplete = true; } else { // add it to the inputString: inputString[inputPos] = inChar; inputPos++; } } else { // Incoming message too long. Throw away inputPos = 0; } } }
Any help will be highly appreciated
-
RE: 💬 Wall Socket Insertable Node
@Koresh Ok, I am looking forward to hear how your board turns out. So what I am looking for is something to replace this temperature controller. I was thinking about using esp8266 wifi chip instead of the radio, since power is not a big issue since its connected to the power line. Then people like my parents can use it with IFTTT and do not have to add a gateway. I was also thinking about adding a connector for a nextion display, just in case you want to display the temperature, use it as input to set temperature etc. It should also have a better temperature and humidity chip then the one inbuilt I think. Screw terminal to connect floor temperature sensor. Measure power accurately. Well if you would like to cooperate on version2 of your board let me know. I would like to make 20 units or so for now.
-
RE: My MYSX Multisensors board
Any update on this one? Chinese new year is over now...
-
RE: 💬 Wall Socket Insertable Node
@Koresh
Check out this interesting topic on accursy for power measurement:
GregDo you have data on the inbuilt temperature sensor?
-
RE: 💬 Wall Socket Insertable Node
Hi, will it also measure voltage or just current? Because to calculate power you need voltage as well? Is it possible to add dht22 and one wire temperature sensor to it as well, then it could replace all the temperature controllers for heating cables.
-
RE: openHAB binding
@bkl Thanks for your code, just to be sure, you only have 1 LED in your LED strip? NUM_LEDS = 1 or does that define child ID? In mine I have 38, 52,43,78,23,67 leds in my ledstrips. How can I modify your code to be used as locally attached sensor on the gateway? Also I have 6 ledstrip connected to my gateway.
Copyright 2015 Sensnology | Forum Guidelines | Privacy Policy | Terms of Service
-
RE: IR node
@mfalkvidd , Thanks for the tip:) I saw some other IR codes in the forum, but @BartE code seems the most promissing. Do you think I can modify his code to achieve what I want?
On OpenHab which I use as controller I will then send something similiar to this then when I want(single button in OH): to turn on my TV, select correct input source on my stereo, select correct hdmi channel:
12;7;1;1;32;NEC,0xa8bca 12;7;1;1;32;NEC,0xa54bca 12;7;1;1;32;NEC,0xa62ca
-
RE: openHAB binding
I am amazed by your work @bkl !
I have a few question for you:
Can I use your binding somehow to integrate RGB light in openhab with the color wheel? I have some programmable rgb ledstrip that I was thinking about integrating into openhab, but I am unsure how to do this. I was thinking about using the color widget in the sitemap together with a DMX syntax:if my led strip has 56 diodes
Color rgb_strip_living_room "RGB Ledstrip Living Room" {dmx="CHANNEL[0-56]"}.
But then i could also use the same ledstrip in 2 by setting two different color like
Color rgb_strip_living_room2 "RGB Ledstrip Living Room" {dmx="CHANNEL0-23]"} Color rgb_strip_living_room3 "RGB Ledstrip Living Room" {dmx="CHANNEL24-56]"}
Then I would also like to send IR commands from OH to mysensor, have any of you done that?
Keep up the great work, and let me know if I somehow can help with expanding/documenting the binding.
-
IR node
Hi
I have connected my IR node to my serial gateway, however I have a wish that my controller(Opnehab on RPI) can send out NEC,xxxxxx to my gateway which then forwards it to the node. This way I do not need to recompile my node everytime I want to add a new IR command. Is it possible to achieve this? I had a glance at the IR code provided here:void incomingMessage(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type==V_LIGHT) { int incomingRelayStatus = message.getInt(); if (incomingRelayStatus == 1) { irsend.send(NEC, 0x2AA22DD, 32); // Vol up yamaha ysp-900 } else { irsend.send(NEC, 0x1EE1F807, 32); // Vol down yamaha ysp-900 } // Start receiving ir again... irrecv.enableIRIn(); } }
How has other people implemented IR commands?
-
RE: openHAB binding
Hi all,
can we please document this binding and add it to github of openhab in similiar way to all other bindings? I can help with doing so:) -
RE: Locally attached sensors
@mfalkvidd said:
#define MY_GATEWAY_SERIAL
The define method got rid of that error, so then i Should add it to the constructor?
So that the user that creates the node have to decide if the gateway is serial,wifi, or RF, right?
Now I got these errors instead:
Arduino: 1.6.8 (Windows 7), Board: "Arduino Nano, ATmega328" Build options changed, rebuilding all C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:8:1: error: expected initializer before 'boolean' boolean SLEEP_MODE // Watt-value can only be reported when sleep mode is false. ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: In constructor 'EnergyMeter::EnergyMeter(int)': C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:27:2: error: 'CHILD_ID' was not declared in this scope CHILD_ID = _CHILD_ID; // Id of the sensor child ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:30:2: error: 'SEND_FREQUENCY' was not declared in this scope SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:31:2: error: 'PULSE_FACTOR' was not declared in this scope PULSE_FACTOR =1000; // Nummber of blinks per KWH of your meeter ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:32:2: error: 'SLEEP_MODE' was not declared in this scope SLEEP_MODE = false ; // Watt-value can only be reported when sleep mode is false. ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:33:2: error: 'MAX_WATT' was not declared in this scope MAX_WATT = 10000; // Max watt value to report. This filetrs outliers. ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:34:2: error: 'DIGITAL_INPUT_SENSOR' was not declared in this scope DIGITAL_INPUT_SENSOR = 0; // Usually the interrupt = pin -2 (on uno/nano anyway) ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:38:2: error: 'ppwh' was not declared in this scope ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:51:18: error: 'INTERRUPT' was not declared in this scope attachInterrupt(INTERRUPT, onPulse, RISING); ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:51:29: error: 'onPulse' was not declared in this scope attachInterrupt(INTERRUPT, onPulse, RISING); ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: At global scope: C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:59:6: error: 'ENERGYMETER' has not been declared void ENERGYMETER::present(){ ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: In function 'void present()': C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:64:11: error: 'CHILD_ID' was not declared in this scope present(CHILD_ID, S_POWER); ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: At global scope: C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:69:6: error: 'ENERGYMETER' has not been declared void ENERGYMETER::update(){ ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: In function 'void update()': C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:73:36: error: 'SEND_FREQUENCY' was not declared in this scope bool sendTime = now - lastSend > SEND_FREQUENCY; ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:74:7: error: 'pcReceived' was not declared in this scope if (pcReceived && (SLEEP_MODE || sendTime)) { ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:74:22: error: 'SLEEP_MODE' was not declared in this scope if (pcReceived && (SLEEP_MODE || sendTime)) { ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:79:32: error: 'MAX_WATT' was not declared in this scope if (watt<((unsigned long)MAX_WATT)) { ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:80:14: error: 'wattMsg' was not declared in this scope send(wattMsg.set(watt)); // Send watt value to gw ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:89:12: error: 'pcMsg' was not declared in this scope send(pcMsg.set(pulseCount)); // Send pulse count value to gw ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:90:49: error: 'PULSE_FACTOR' was not declared in this scope double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:93:14: error: 'kwhMsg' was not declared in this scope send(kwhMsg.set(kwh, 4)); // Send kwh value to gw ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:100:13: error: 'CHILD_ID' was not declared in this scope request(CHILD_ID, V_VAR1); ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:104:7: error: 'SLEEP_MODE' was not declared in this scope if (SLEEP_MODE) { ^ C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp: At global scope: C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:109:1: error: expected declaration before '}' token } ^ exit status 1 Error compiling for board Arduino Nano. This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.
-
RE: Locally attached sensors
I now get this error message, any idea what the problem might be?
In file included from C:\Users\kim\Documents\Arduino\libraries\EnergyMeter\EnergyMeter.cpp:5:0: C:\Users\kim\Documents\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless.
Here is my test class:
#include <EnergyMeter.h> EnergyMeter power(1);//initialize an instance of the class void setup(){ power.present(); } void loop(){ power.update();//stay one second on, then a second off }
and here is my EnergyMeter.cpp file :
#include "EnergyMeter.h" //include the declaration for this class #include <SPI.h> #include <MySensor.h> long PULSE_FACTOR // Nummber of blinks per KWH of your meeter boolean SLEEP_MODE // Watt-value can only be reported when sleep mode is false. long MAX_WATT // Max watt value to report. This filetrs outliers. int DIGITAL_INPUT_SENSOR // Usually the interrupt = pin -2 (on uno/nano anyway) int CHILD_ID // Id of the sensor child unsigned long SEND_FREQUENCY double ppwh boolean pcReceived = false; volatile unsigned long pulseCount = 0; volatile unsigned long lastBlink = 0; volatile unsigned long watt = 0; unsigned long oldPulseCount = 0; unsigned long oldWatt = 0; double oldKwh; unsigned long lastSend; //<<constructor>> setup the LED, make pin 13 an OUTPUT EnergyMeter::EnergyMeter(int _CHILD_ID){ CHILD_ID = _CHILD_ID; // Id of the sensor child /* Optional Arguments */ SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. PULSE_FACTOR =1000; // Nummber of blinks per KWH of your meeter SLEEP_MODE = false ; // Watt-value can only be reported when sleep mode is false. MAX_WATT = 10000; // Max watt value to report. This filetrs outliers. DIGITAL_INPUT_SENSOR = 0; // Usually the interrupt = pin -2 (on uno/nano anyway) /*Starting the setup algorithm */ ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour MyMessage wattMsg(CHILD_ID,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); // Fetch last known pulse count value from gw request(CHILD_ID, V_VAR1); // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output // If no pullup is used, the reported usage will be too high because of the floating pin pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP); attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); } //<<destructor>> EnergyMeter::~EnergyMeter(){/*nothing to destruct*/} //present it void ENERGYMETER::present(){ // Send the sketch version information to the gateway and Controller sendSketchInfo("Energy Meter", "1.0"); // Register this device as power sensor present(CHILD_ID, S_POWER); } //update the reading of the power void ENERGYMETER::update(){ unsigned long now = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { // New watt value has been calculated if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt<((unsigned long)MAX_WATT)) { send(wattMsg.set(watt)); // Send watt value to gw } Serial.print("Watt:"); Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { send(pcMsg.set(pulseCount)); // Send pulse count value to gw double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } } void receive(const MyMessage &message) { if (message.type==V_VAR1) { pulseCount = oldPulseCount = message.getLong(); Serial.print("Received last pulse count from gw:"); Serial.println(pulseCount); pcReceived = true; } } void onPulse() { if (!SLEEP_MODE) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 /interval) / ppwh; lastBlink = newBlink; } pulseCount++; }
-
RE: Locally attached sensors
Here is my suggestion, which does not quite work, because I dont know how to make the loop inside a class:)
#include "ENERGYMETER.h" //include the declaration for this class #include <SPI.h> #include <MySensor.h> #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. int DIGITAL_INPUT_SENSOR // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 1 // Id of the sensor child unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour boolean pcReceived = false; volatile unsigned long pulseCount = 0; volatile unsigned long lastBlink = 0; volatile unsigned long watt = 0; unsigned long oldPulseCount = 0; unsigned long oldWatt = 0; double oldKwh; unsigned long lastSend; MyMessage wattMsg(CHILD_ID,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); const byte LED_PIN = 13; //use the LED @ Arduino pin 13, this should not change so make it const (constant) //<<constructor>> setup the LED, make pin 13 an OUTPUT ENERGYMETER::ENERGYMETER(_DIGITAL_INPUT_SENSOR){ DIGITAL_INPUT_SENSOR = _DIGITAL_INPUT_SENSOR; // Fetch last known pulse count value from gw request(CHILD_ID, V_VAR1); // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output // If no pullup is used, the reported usage will be too high because of the floating pin pinMode(DIGITAL_INPUT_SENSOR,INPUT_PULLUP); attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); } //<<destructor>> ENERGYMETER::~ENERGYMETER(){/*nothing to destruct*/} //present it void ENERGYMETER::present(){ // Send the sketch version information to the gateway and Controller sendSketchInfo("Energy Meter", "1.0"); // Register this device as power sensor present(CHILD_ID, S_POWER); } //turn the LED off void ENERGYMETER::start(){ void loop() { unsigned long now = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { // New watt value has been calculated if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt<((unsigned long)MAX_WATT)) { send(wattMsg.set(watt)); // Send watt value to gw } Serial.print("Watt:"); Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { send(pcMsg.set(pulseCount)); // Send pulse count value to gw double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } } void receive(const MyMessage &message) { if (message.type==V_VAR1) { pulseCount = oldPulseCount = message.getLong(); Serial.print("Received last pulse count from gw:"); Serial.println(pulseCount); pcReceived = true; } } void onPulse() { if (!SLEEP_MODE) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 /interval) / ppwh; lastBlink = newBlink; } pulseCount++; }
-
Locally attached sensors
My serial gateway will have something like 16 locally attached sensor to it. So I would like to keep my serial gateway code as clean and simple as possible, hence I would like some input on how to do this.
I will take the energyMeterPulse sketch in the example folder as an example of my idea.
I would like to rewrite the code to have an constructur like this:
EnergyMeter(DIGITAL_INPUT_SENSOR,PULSE_FACTOR ,SLEEP_MODE,MAX_WATT,CHILD_ID,SEND_FREQUENCY)
Then it should have three methods:
Present Start Stop
My serial gateway code will then look clean:
void setup() { // Setup locally attached sensors EnergyMeter powerSensor1 = new EnergyMeter(2,1000,false,10000,12,60000) } void presentation() { // Present locally attached sensors powerSensor1.present } void loop() { // Send locally attached sensor data here powerSensor1.start }
So how can I restructure energyMeterPulse sketch to achieve this? Or how does other handle heaps of locally attached sensor to gateway?
-
RE: Serial gateway with several sensors connected to it
@barduino
Upgrading to Arduino 1.6.8 did the trick.
Thanks. -
RE: Serial gateway with several sensors connected to it
I will then delete C:\Users\kim\Documents\Arduino which the ide creates.. Will upgrtade today, and let you know how it goes
-
RE: Serial gateway with several sensors connected to it
@sundberg84
So which directory should i put the files in? BOth hardware and library? -
RE: Serial gateway with several sensors connected to it
@sundberg84
So the IDE by default get installed C:\Program Files (x86)\Arduino but the files folder get default set to this:C:\Users\kim\Documents\Arduino
I guess arduino made it that way so that you can load examples from C:\Program Files (x86)\Arduino then mess around with them and save them here C:\Users\kim\Documents\Arduino
So I never had duplicate files, i tried both locations without sucsess. So which version of the IDE should I use? 1.6.7 is what I have now.
-
RE: Serial gateway with several sensors connected to it
Well I tried to save it both here:
C:\Program Files (x86)\Arduino\libraries\Mysensor
C:\Program Files (x86)\Arduino\hardware\MySensorsAs well as here as described in your link:
C:\Users\kim\Documents\ArduinoBut I get compile errors no matter where I try to compile serialgateway on due which I found in the C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway
Cheers
-
RE: Serial gateway with several sensors connected to it
@AWI How do I Install the development branch correctly? Does it only work with nano 328?
-
RE: Serial gateway with several sensors connected to it
@AWI
I just copied all the files in libraries and hardware in the development zip into c:\program files\Arduino\I am trying to get it to run on arduino due and yes I was trying the run the Serial gateway in Library\My Sensor\SerialGateway
-
RE: Serial gateway with several sensors connected to it
@AWI
So I copied ower evrything in the library folder of the development branch. When i then try to compile the serial gateway i get this error:Arduino: 1.6.7 (Windows 7), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Serial, 115200, 4M (3M SPIFFS)" In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:50:0: C:\Program Files (x86)\Arduino\libraries\MySensors/MySensor.h:285:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^ In file included from C:\Program Files (x86)\Arduino\libraries\MySensors\examples\SerialGateway\SerialGateway.ino:52:0: C:\Program Files (x86)\Arduino\libraries\PinChangeInt/PinChangeInt.h:103:19: fatal error: new.h: No such file or directory #include <new.h> ^ compilation terminated. exit status 1 Error compiling. This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.
-
RE: Serial gateway with several sensors connected to it
@TimO
I will look into it, however first I need to get the gateway up running.So I am struggling to see how locally attached sensors work. I guess (reading several forum entry) that gw object is not needed. What is this inclusion mode? Is that part of the code needed?
However I can not get my code to compile:
#include <SPI.h> #include <MySensor.h> // Enable debug prints to serial monitor #define MY_DEBUG // Enable serial gateway #define MY_GATEWAY_SERIAL // Flash leds on rx/tx/err #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 DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor. (Only 2 and 3 generates interrupt!) #define PULSE_FACTOR 1000 // Nummber of blinks per KWH of your meeter #define SLEEP_MODE false // Watt-value can only be reported when sleep mode is false. #define MAX_WATT 10000 // Max watt value to report. This filetrs outliers. #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway) #define CHILD_ID 9 // Id of the sensor child unsigned long SEND_FREQUENCY = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway. MySensor gw; double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour boolean pcReceived = false; volatile unsigned long pulseCount = 0; volatile unsigned long lastBlink = 0; volatile unsigned long watt = 0; unsigned long oldPulseCount = 0; unsigned long oldWatt = 0; double oldKwh; unsigned long lastSend; MyMessage wattMsg(CHILD_ID,V_WATT); MyMessage kwhMsg(CHILD_ID,V_KWH); MyMessage pcMsg(CHILD_ID,V_VAR1); void setup() { attachInterrupt(INTERRUPT, onPulse, RISING); lastSend=millis(); } void presentation() { // Present locally attached sensors here // Register this device as power sensor gw.present(CHILD_ID, S_POWER,"Energy Meter"); } void loop() { gw.process(); unsigned long now = millis(); // Only send values at a maximum frequency or woken up from sleep bool sendTime = now - lastSend > SEND_FREQUENCY; if (pcReceived && (SLEEP_MODE || sendTime)) { // New watt value has been calculated if (!SLEEP_MODE && watt != oldWatt) { // Check that we dont get unresonable large watt value. // could hapen when long wraps or false interrupt triggered if (watt<((unsigned long)MAX_WATT)) { gw.send(wattMsg.set(watt)); // Send watt value to gw } //Serial.print("Watt:"); //Serial.println(watt); oldWatt = watt; } // Pulse cout has changed if (pulseCount != oldPulseCount) { //gw.send(pcMsg.set(pulseCount)); // Send pulse count value to gw double kwh = ((double)pulseCount/((double)PULSE_FACTOR)); oldPulseCount = pulseCount; if (kwh != oldKwh) { gw.send(kwhMsg.set(kwh, 4)); // Send kwh value to gw oldKwh = kwh; } } lastSend = now; } else if (sendTime && !pcReceived) { // No count received. Try requesting it again request(CHILD_ID, V_VAR1); lastSend=now; } if (SLEEP_MODE) { sleep(SEND_FREQUENCY); } } void incomingMessage(const MyMessage &message) { if (message.type==V_VAR1) { pulseCount = oldPulseCount = message.getLong(); //Serial.print("Received last pulse count from gw:"); //Serial.println(pulseCount); pcReceived = true; } } void onPulse() { if (!SLEEP_MODE) { unsigned long newBlink = micros(); unsigned long interval = newBlink-lastBlink; if (interval<10000L) { // Sometimes we get interrupt on RISING return; } watt = (3600000000.0 /interval) / ppwh; lastBlink = newBlink; } pulseCount++; }
-
RE: Serial gateway with several sensors connected to it
@TimO
From the link:- Arduino Uno 9 8 10
Can I not use rx/tx on my node arduino? (Pin 0/1)
Same goes for my gateway, currently I am using pin 10/11. If I can fix this in software it would be better, then i dont have to resolder my setup, also what happens when you have two rs232 nodes connected to the gateway?
-
RE: Serial gateway with several sensors connected to it
@AWI
1: Yes it is, baudrate 115200
2: OK
3: I am using software serial at 9600(long cables) instead of 485 because then i dont need extra hardware.
4: yes, LDR,6 rgb strip,IR sender,IR emitter are connected directlySo from there on...
1: How to modify the code to use software serial instead of radio/485?
2:
bar.ino should then have:MyMessage msgWine(CHILD_ID_SPRIT, V_STATUS); //and in the loop gw.send(msgWine.set(0)); #ifdef MY_DEBUG Serial.println("Sprit opp"); #endif
Now it will send that message out everytime the button is pressed, so I need to modify the code a bit to only send it out if it once every 12s(yes you need to hold the button for 12s to run the motor to the end.) I guess the best would be to rewrite the arduino code so that a single push on the button runs the motor for 12s instead of holding it in for 12s.
Thanks for the help so far...
-
RE: Serial gateway with several sensors connected to it
@TimO
So I have made a sketch of my setup:I also started to modify the bar.ino code with the input from you:
// Enable debug prints //#define MY_DEBUG #include <MySensor.h> #define CHILD_ID_SPRIT 0 #define CHILD_ID_WINE 1 #SLEEP_TIME 0 //unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds) // constants won't change. They're used here to // set pin numbers: const int buttonPinSpritOpp = 9; // the number of the pushbutton pin const int buttonPinSpritNed = 12; // the number of the pushbutton pin const int buttonPinVinOpp = 10; // the number of the pushbutton pin const int buttonPinVinNed = 11; // the number of the pushbutton pin const int ledPinSpritOpp = 4; // the number of the pushbutton pin const int ledPinSpritNed = 8; // the number of the pushbutton pin const int ledPinVinOpp = 7; // the number of the pushbutton pin const int ledPinVinNed = 3; // the number of the pushbutton pin const int motorPinVin = A3; // the number of the motor pin const int motorPinOnVin =A1; const int motorPinOnSprit = A2;// const int motorPinSprit = A0; // the number of the motor pin int intCode =-1; MyMessage msgHum(CHILD_ID_SPRIT, V_STATUS); MyMessage msgTemp(CHILD_ID_WINE, V_STATUS); void setup() { // initialize the motor pin as an output: pinMode(motorPinSprit, OUTPUT); pinMode(motorPinVin, OUTPUT); pinMode(motorPinOnSprit, OUTPUT); pinMode(motorPinOnVin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPinSpritOpp, INPUT_PULLUP); pinMode(buttonPinSpritNed, INPUT_PULLUP); pinMode(buttonPinVinOpp, INPUT_PULLUP); pinMode(buttonPinVinNed, INPUT_PULLUP); // Default values digitalWrite(motorPinSprit,HIGH); digitalWrite(motorPinVin,HIGH); digitalWrite(motorPinOnSprit, HIGH); digitalWrite(motorPinOnVin, HIGH); } void presentation() { // Send the Sketch Version Information to the Gateway sendSketchInfo("BAR", "1.0"); // Register all sensors to gw (they will be created as child devices) present(CHILD_ID_SPRIT, S_BINARY); present(CHILD_ID_WINE, S_BINARY); } void loop() { if ((digitalRead(buttonPinSpritOpp) == HIGH && digitalRead(buttonPinSpritNed) == LOW) || intCode==1) { digitalWrite(motorPinSprit,LOW); digitalWrite(motorPinOnSprit,LOW); digitalWrite(ledPinSpritOpp,HIGH); digitalWrite(ledPinSpritNed,LOW); send(msg.set(0)); #ifdef MY_DEBUG Serial.println("Sprit opp"); #endif } else if ((digitalRead(buttonPinSpritOpp) == LOW && digitalRead(buttonPinSpritNed) == HIGH)|| intCode==2) { digitalWrite(motorPinSprit,HIGH); digitalWrite(motorPinOnSprit,LOW); digitalWrite(ledPinSpritNed,HIGH); digitalWrite(ledPinSpritOpp,LOW); send(msg.set(1)); #ifdef MY_DEBUG Serial.println("Sprit ned"); #endif } else{ digitalWrite(motorPinSprit,HIGH); digitalWrite(motorPinOnSprit,HIGH); digitalWrite(ledPinSpritOpp,LOW); digitalWrite(ledPinSpritNed,LOW); } if ((digitalRead(buttonPinVinOpp) == HIGH && digitalRead(buttonPinVinNed) == LOW) || intCode==3) { digitalWrite(motorPinOnVin,LOW); digitalWrite(motorPinVin,LOW); digitalWrite(ledPinVinOpp,HIGH); digitalWrite(ledPinVinNed,LOW); send(msg.set(0)); #ifdef MY_DEBUG Serial.println("Vin opp"); #endif } else if ((digitalRead(buttonPinVinOpp) == LOW && digitalRead(buttonPinVinNed) == HIGH)|| intCode==4) { digitalWrite(motorPinVin,HIGH); digitalWrite(motorPinOnVin,LOW); digitalWrite(ledPinVinNed,HIGH); digitalWrite(ledPinVinOpp,LOW); send(msg.set(1)); #ifdef MY_DEBUG Serial.println("Vin ned"); #endif } else { digitalWrite(motorPinVin,HIGH); digitalWrite(motorPinOnVin,HIGH); digitalWrite(ledPinVinOpp,LOW); digitalWrite(ledPinVinNed,LOW); } if (intCode==0){ digitalWrite(motorPinOnVin,HIGH); digitalWrite(motorPinOnSprit,HIGH); digitalWrite(ledPinSpritOpp,LOW); digitalWrite(ledPinSpritNed,LOW); digitalWrite(ledPinVinOpp,LOW); digitalWrite(ledPinVinNed,LOW); #ifdef MY_DEBUG Serial.println("Shutting off"); #endif } } sleep(SLEEP_TIME); //sleep a bit } 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 if message.sensor == CHILD_ID_SPRIT){ if message.getBool(){ intCode = 1; else{ intCode = 2; } } if message.sensor == CHILD_ID_WINE){ if message.getBool(){ intCode = 3; else{ intCode = 4; } } // 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()); }
There are a few things unclear to me: How do I define the baudrate of the serial?
Then its the actual sending to the gateway:send(msg.set(0));
so how does this msg object work? I need two of these objects one for child node 1 and for child node 2 right?
Then lets move to the RPI, This will then send out 1;2;3;0;2;1/n which then should send it to the gateway arduino which then parses this and send it out with baudrate 9600 on software serial on pin 11, which then will be received by the code above and the wine comes down.
So how should my serial gateway sketch look like? And how do I get feedback from my node (rx pin 10 on due) back to RPI?
Thanks for the tips so far:)
-
RE: openHAB binding
@bkl
Note2: If you are using non standard serial ports you have to adapt start.sh to have the serial port included. the java command line should then include the following parameters:-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0
whereas ttyAMA0 is the path to your serial port. Please be aware to change all scripts you might use for startup (debug, automatic start in linux,...)So my question (linux newbie) is what is the best way to attach my Arduino nano to rpi, so that it always find it on reboot or if it is unplugged/replugged.
Is this correct and will this work with the binding?
/etc/udev/rules.d/99-usb-serial.rules"with my device info:
SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", ATTRS{serial}=="A40360T2", SYMLINK+="ttyUSB99" -
Serial gateway with several sensors connected to it
I am new to the mysensor enviroment, but I have been using arduino for a long time now.
So I have a smarthome setup with openhab rpi connected to an arduino nano 328p on serial.
Currently I have 3 sensors(not sure if you can rgb strip sensor though) connected to the nano (gateway) and another nano connected over software serial to the gateway(node 1). So currently I am not using RF at all.
So I have taken baby step and written 4 independent sketches for my nano and tested them succsessfully, however I now need to integrate them into openhab and hence I turned to mysensor. I tried reading up on the API and tutorials: http://forum.mysensors.org/topic/1194/tutorial-openhab-with-serial-gateway
so below are my four independent codes:
https://github.com/skatun/Openhab/blob/master/Bar3.ino
https://github.com/skatun/Openhab/blob/master/power7.ino
https://github.com/skatun/Openhab/blob/master/rgb.ino
https://github.com/skatun/Openhab/blob/master/IRsend.inoSo I need to rewrite the code to send out/read in the Serial API and this is where I am bit stuck.
So currently my send method of the powerMeter looks like:
Serial.print(power); Serial.print(' '); Serial.println(pulseCount * whPerPulse); // watt hour elapsed
but can I just rewrite this to:
gw.send(power);
the other 3 sketches does not send anything but just receives messages from my RPI.
So can anyone point me in the right direction of how to modify my code to fit inside the mysensor enviroment, or is mysensor to much overhead for my setup that i rather should use a simpler approach?
Any help and hint would be great:)
-
RE: Serial Gateway
@tbowmo From that developers page i get the libraries, but somehow i can not find the serial tutorial for DHT11. I found this: link
Yes and you are completly right ""Nodes" they mean independent arduinos" ,These nodes can then be placed all over the house,. However i had the chance when i rebuilt my flat my flat to run empty pipes all over the place to my fusebox. Since arduino needs power I dont see why i should run 2 wires, when i can run4 wires and skip the hole RF part.
When I am finished my system would look like:
1 arduino Mega in fusebox with 6 dht22 sensors ,12 motion sensors, 6 light sensor, 6CO sensors, 4 led strips connected to it. USB to RPI(0.3m)
1 arduino micro 3.3V under kitchen, with ledstrip , a servo(gate for roomba), 1 IR transmitter RS485 or serial to RPI(8m)
1 arduino micro 3.3V in bar with led strip, 4 relays and 4 buttons RS485 or serial to RPI(14m)
1 arduino micro 3.3V in tv bench, ledstrip,1 relay for tv lift and 2 butttons RS485 or serial to RPI( 9m)
1 arduino micro 3.3V in hallway,ledstrip,1 relay for electric wardrobe and 3 buttons RS485 or serial to RPI(2m)
1 arduino micro 3.3V at balcony, ledstrip,7 relays for hetater, rollers,BBQ,hammock etc, 6 buttons RS485 or serial to RPI(17m)But currently i am just installing the the arduino nano in fusebox with a ledstrip and dht11 sensor to it. Start simple...
-
RE: Serial Gateway
This is how i have normally done similiar task before i started looking into mysensor.
#include "DHT.h" DHT dht; pinsDHT = (2,4,7,8,10,12) childNode = (0,1,2,3,4,5) int GatewayID = 1 void setup() { Serial.begin(9600); for (int i=0 ;i<6:i++) { dht(i).setup(pinsDHT(i)); // data pin 2 } } void loop() { //delay(dht.getMinimumSamplingPeriod()); for (int i=0 ;i<6:i++) { Serial.print(GatewayID); Serial.print(","); Serial.print(childNode(i)); Serial.print(","); Serial.print(1); Serial.print(","); Serial.print(S_TEMP); Serial.print(","); Serial.print(dht(i).getTemperature()); Serial.print("\n"); //debug Serial.println(); Serial.print(GatewayID); Serial.print(","); Serial.print(childNode(i)); Serial.print(","); Serial.print(1); Serial.print(","); Serial.print(S_HUM); Serial.print(","); Serial.print(dht(i).getHumidity()); Serial.print("\n"); //debug Serial.println(); } }```
-
RE: Serial Gateway
@drock1985 I can help you with the openhab binding.. How can i modify this code so that it prints it out on serial instead of transmitting on RF?
-
RE: Serial Gateway
@tbowmo Yes it is connected directly to nano. When i have 6 nodes, will you collect them in an array or define them 6 objects? Do you have a link to dev branch?
-
Serial Gateway
Hi
I am struggling to figure out how to use the serial API, the protocol is easy to understand, but how to implement is harder.I have an arduino nano that i would like to use as the gateway, to this i have 6 dht11 humidity/temperature sensors attached and 4 led strips. The ledstrips currently uses the neopixel library.
The nano is attached to a rpi running openhab through usb(maybe i should use the serial on gpio instead?), i have made simple arduino sketch that test the serial protocol
Serial.print(13;7;1;0;2;1\n)
and the open hab intpretates it nicely. But now I am stuck, how can i modify the humidity code to send it out on serial protocol? And can I somehow make an array of DHT object and loop through them? And how can i combine the neopixel into the serial.api? How should the message look like coming into the serial from openhab?Any help is highly appreciated:)
-
RE: Serial gateway with the API
@skatun said:
gw.send(msgTemp.set(temperature, 1));
So if I understand you correctly in the development version the method gw.send will then be equal to :
Serial.print(GwId,NodeID,1,0,msgTemp.set(temperature, 1)\n)And in the examples I will then just comment out all the serial.print statements or?
Thanks
-
Serial gateway with the API
Hi
I am pretty new to the mysensor project, but I really like it!So I have a few questions regarding my setup. So I have an Raspberry Pi running openhab, to this I am trying to connect 4 arduinos, 3 of them through usb and the last one through voltage converter and serial on GPIO. I am currently making 6 sensor nodes
Each nodes has 2 pir sensors, dht22,light sensor, sound sensor, and co2 sensor. Due to the processing load, my idea was to split these sensors over two arduino uno(atmega 328). Is that a good idea? (The problem is that I am trying to detect which of the two pir sensor were triggered first to see if you are going in or out of the room, hence they will get triggered with >50ms interval).
Then i have the serial on GPIO arduino nano(due to the fact it was easier to solder 12m cable to the gpio pins instead of terminating it to the usb.) which reads 4 buttons and controlls 4 solid state relays for my bar.
Then finally I have a arduino controlling several led strips, connected through USB.
So as a start I managed to get the serial gateway to work by just writing serial.print("12,7,1,0,23.6\n") but now I want to expand it to use real sensors and this is when i get stuck.... Do I need to throw away the libraries since these only work with the radio modem, or should i rewrite them to work with the serial connection or how do I proceed? I need to set the baudrate and give them static node ID. Below is my modified code, that does not work..
#include <SPI.h> #include <MySensor.h> #include <DHT.h> #define CHILD_ID_HUM 0 #define CHILD_ID_TEMP 1 #define HUMIDITY_SENSOR_DIGITAL_PIN 11 unsigned long SLEEP_TIME = 1000; // Sleep time between reads (in milliseconds) MySensor gw; DHT dht; float lastTemp; float lastHum; boolean metric = true; MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); void setup() { gw.begin(NULL,12); dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); // Send the Sketch Version Information to the Gateway gw.sendSketchInfo("Humidity", "1.0"); // Register all sensors to gw (they will be created as child devices) gw.present(CHILD_ID_HUM, S_HUM); gw.present(CHILD_ID_TEMP, S_TEMP); metric = gw.getConfig().isMetric; } void loop() { delay(dht.getMinimumSamplingPeriod()); float temperature = dht.getTemperature(); if (isnan(temperature)) { Serial.println("Failed reading temperature from DHT"); } else if (temperature != lastTemp) { lastTemp = temperature; if (!metric) { temperature = dht.toFahrenheit(temperature); } gw.send(msgTemp.set(temperature, 1)); Serial.print("T: "); Serial.println(temperature); } float humidity = dht.getHumidity(); if (isnan(humidity)) { Serial.println("Failed reading humidity from DHT"); } else if (humidity != lastHum) { lastHum = humidity; gw.send(msgHum.set(humidity, 1)); Serial.print("H: "); Serial.println(humidity); } gw.sleep(SLEEP_TIME); //sleep a bit }
Thanks for any feedback