Domotiga and Envi on USB
Moderator: RDNZL
Domotiga and Envi on USB
I have been trying to get Domotiga to see my Envi currentcost monitor with the provided usb cable.
If I set the port as follows:
stty crtscts cs7 -parodd -cstopb 57600 </dev/ttyUSB1
stty -a < /dev/ttyUSB1
...confirms baud rate setting.
Then, I get this kind of output with minicom with the same settings 57600 7E1
<msg><src>CC128v0.15</src><dsb>00001</dsb><time>17:35:05</time><tmprF>72.3</tmprF><sensor>0</sensor><id>00077
</id><type>1</type><ch1>watts></ch2></msg>
Sometime it messes up a little, but they are talking.
I cant get Domotiga to see this.
Can anyone suggest how to proceed?
Thanks,
Andy
If I set the port as follows:
stty crtscts cs7 -parodd -cstopb 57600 </dev/ttyUSB1
stty -a < /dev/ttyUSB1
...confirms baud rate setting.
Then, I get this kind of output with minicom with the same settings 57600 7E1
<msg><src>CC128v0.15</src><dsb>00001</dsb><time>17:35:05</time><tmprF>72.3</tmprF><sensor>0</sensor><id>00077
</id><type>1</type><ch1>watts></ch2></msg>
Sometime it messes up a little, but they are talking.
I cant get Domotiga to see this.
Can anyone suggest how to proceed?
Thanks,
Andy
Re: Domotiga and Envi on USB
The output has less problems with:
stty crtscts cs8 -evenp -cstopb 57600 </dev/ttyUSB1
However, even with a unit number of 1, i still have no luck
I ordered a TTL-RS232 convertor though
stty crtscts cs8 -evenp -cstopb 57600 </dev/ttyUSB1
However, even with a unit number of 1, i still have no luck
I ordered a TTL-RS232 convertor though
- RDNZL
- Forum Moderator
- Posts: 1008
- Joined: Sun Sep 24, 2006 1:45 pm
- Location: Dordrecht, The Netherlands
- Contact:
Re: Domotiga and Envi on USB
The default/fixed settings of DomotiGa's CurrentCost serial port are 8N1, so 8 bits, no parity and 1 stop bit.
Does it output correctly if you use those parameters for stty?
I never had to play with stty , and I have a lot of serial/usb devices.
Does it output correctly if you use those parameters for stty?
I never had to play with stty , and I have a lot of serial/usb devices.
Regards, Ron.
Re: Domotiga and Envi on USB
I've never played with stty before either. I just sat down last night with a six pack and 'man stty'
I did notice that the terminal program in DomotiGa only supports a baud rate of 38400 max, so I used minicom.
Also, I could not source a regular CC128>RS232 cable anywhere. I found the plug pinouts on google and ...I'm building one when the parts arrive. (I live in Western Canada, and it can take a while for anything to get here!).
I'm going to try and get the USB cable working though, since this is what all the units ship with now.
Thanks for your help,
Andy
I did notice that the terminal program in DomotiGa only supports a baud rate of 38400 max, so I used minicom.
Also, I could not source a regular CC128>RS232 cable anywhere. I found the plug pinouts on google and ...I'm building one when the parts arrive. (I live in Western Canada, and it can take a while for anything to get here!).
I'm going to try and get the USB cable working though, since this is what all the units ship with now.
Thanks for your help,
Andy
Re: Domotiga and Envi on USB
Hey guys,
I've done some more investigating. I still only have the USB lead. Santa missed my tech letter!
This is the output from minicom: 57600-8-N-1 on /dev/ttyUSB1
<msg><src>CC128-v0.15</src><dsb>00020</dsb><time>21:43:39</time><tmprF>69.7</tmprF><sensor>0</sensor><id>00077</id><type>1
</type><ch1><watts>00463</watts></ch1><ch2><watts>00624</watts></ch2></msg>
<msg><src>CC128-v0.15</src><dsb>00020</dsb><time>21:43:45</time><tmprF>69.7</tmprF><sensor>0</sensor><id>00077</id><type>1
</type><ch1><watts>00464</watts></ch1><ch2><watts>00633</watts></ch2></msg>
(ignore the wrapping problems, everything between <msg></msg> appears on separate lines)
In CC module, have /dev/ttyUSB1 and unit set to 20
It will not capture device/show data
If I lock the port with minicom, I get:
2010/12/29 21:43:38 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:38 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:50 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:50 [CurrentCost] Error reading data from serial port! -> End of file
So,
It looks like its trying to open the port, but either not capturing or processing data. Where does DomotiGa store the data?
All I can think of is the code doesnt set the unit number right, or theres some syntax error.
Any ideas? I've not used gambas before. If I modify the class code, do I need to compile?
Thanks
Andy
I've done some more investigating. I still only have the USB lead. Santa missed my tech letter!
This is the output from minicom: 57600-8-N-1 on /dev/ttyUSB1
<msg><src>CC128-v0.15</src><dsb>00020</dsb><time>21:43:39</time><tmprF>69.7</tmprF><sensor>0</sensor><id>00077</id><type>1
</type><ch1><watts>00463</watts></ch1><ch2><watts>00624</watts></ch2></msg>
<msg><src>CC128-v0.15</src><dsb>00020</dsb><time>21:43:45</time><tmprF>69.7</tmprF><sensor>0</sensor><id>00077</id><type>1
</type><ch1><watts>00464</watts></ch1><ch2><watts>00633</watts></ch2></msg>
(ignore the wrapping problems, everything between <msg></msg> appears on separate lines)
In CC module, have /dev/ttyUSB1 and unit set to 20
It will not capture device/show data
If I lock the port with minicom, I get:
2010/12/29 21:43:38 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:38 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:50 [CurrentCost] Error reading data from serial port! -> End of file
2010/12/29 21:43:50 [CurrentCost] Error reading data from serial port! -> End of file
So,
It looks like its trying to open the port, but either not capturing or processing data. Where does DomotiGa store the data?
All I can think of is the code doesnt set the unit number right, or theres some syntax error.
Any ideas? I've not used gambas before. If I modify the class code, do I need to compile?
Thanks
Andy
- RDNZL
- Forum Moderator
- Posts: 1008
- Joined: Sun Sep 24, 2006 1:45 pm
- Location: Dordrecht, The Netherlands
- Contact:
Re: Domotiga and Envi on USB
Running two programs on same port doesn't work. Thats why you see EOF. Data is read by minicom before domotiga can get it.
Regards, Ron.
- RDNZL
- Forum Moderator
- Posts: 1008
- Joined: Sun Sep 24, 2006 1:45 pm
- Location: Dordrecht, The Netherlands
- Contact:
Re: Domotiga and Envi on USB
You device is posting xml with id 00077, and the code has a fixed id of 1
See here domotiga.nl/browser/trunk/DomotiGa/CCur ... .class#L76
You can load the project in IDE, change the 1 to 00077, compile and run and try again?
If that works, I will change the code, so it searches for all <id>pairs and see if there is a device with that address to set the value too.
There was also an issue with some other serial devices in where i had to specify .FlowControl before it worked, I will check that too..
See here domotiga.nl/browser/trunk/DomotiGa/CCur ... .class#L76
You can load the project in IDE, change the 1 to 00077, compile and run and try again?
If that works, I will change the code, so it searches for all <id>pairs and see if there is a device with that address to set the value too.
There was also an issue with some other serial devices in where i had to specify .FlowControl before it worked, I will check that too..
Regards, Ron.
- RDNZL
- Forum Moderator
- Posts: 1008
- Joined: Sun Sep 24, 2006 1:45 pm
- Location: Dordrecht, The Netherlands
- Contact:
Re: Domotiga and Envi on USB
I have changed the code, so enter 00077 as address of the CC128 device you have defined in DomotiGa, and I should use that.
No need to change code line.
No need to change code line.
Regards, Ron.
Re: Domotiga and Envi on USB [Solved]
I solved it! YAY!
I modified the code changing the CHR end of line value to 13 from 10 to read:
I use /dev/ttyUSBD1 (fixed symlink, as per your tutorial), Device is set to "00077" in Domotiga, again as you suggested.
I recompiled a new binary, and it works like a charm - debug shows the xml code properly
I get two readings. Im not sure which is which and They dont seem to add up. But its a start!
If I dont use CHR(13) it doesnt work.My USB cable is white with a black plug. I dont know if the code needs to be different for USB or not.
I'm happy, thanks for the encouragement!
Andy
I modified the code changing the CHR end of line value to 13 from 10 to read:
Code: Select all
PUBLIC SUB CurrentCost_Read()
DIM sData AS String
TRY READ #hCurrentCost, sData, [b]1[/b]
IF ERROR THEN Main.WriteDebugLog(("[CurrentCost] Error reading data from serial port! -> ") & Error.Text)
IF sData = Chr(13) THEN ' buffer until newline then parse
IF Right(sBuffer, 6) = "</msg>" THEN ParseMessage(sBuffer)
sBuffer = NULL
ELSE
sBuffer &= sData
END IF
END
I recompiled a new binary, and it works like a charm - debug shows the xml code properly
I get two readings. Im not sure which is which and They dont seem to add up. But its a start!
If I dont use CHR(13) it doesnt work.My USB cable is white with a black plug. I dont know if the code needs to be different for USB or not.
I'm happy, thanks for the encouragement!
Andy
Re: Domotiga and Envi on USB
I started messing around with the string parsing in CCurrentCost.class and found that none of the values shown in DomotiGa appeared on my envi unit.
I think the current code only looks at one of the phases?
So...... I messed around! Heh heh. This may not be the most elegant way, but now Value4 directly matches the 'Energy Now' value displayed on the Envi
See what you think. Here is the code I violated.....
Thanks and have a Happy New Year
Andy
I think the current code only looks at one of the phases?
So...... I messed around! Heh heh. This may not be the most elegant way, but now Value4 directly matches the 'Energy Now' value displayed on the Envi
See what you think. Here is the code I violated.....
Thanks and have a Happy New Year
Andy
Code: Select all
PUBLIC SUB CurrentCost_Read()
DIM sData AS String
TRY READ #hCurrentCost, sData, 1
IF ERROR THEN Main.WriteDebugLog(("[CurrentCost] Error reading data from serial port! -> ") & Error.Text)
IF sData = Chr(13) THEN ' buffer until newline then parse
'AB - Changed Chr(10) to Chr(13) - now Domotiga gets the string
IF Right(sBuffer, 6) = "</msg>" THEN ParseMessage(sBuffer)
sBuffer = NULL
ELSE
sBuffer &= sData
END IF
END
PUBLIC SUB ParseMessage(sStr AS String)
DIM iDeviceId, EnergyNow AS Integer ' AB- EnergyNow is new
DIM aScan AS String[]
DIM sValue, sValue2, sMaxValue, sTemp AS String 'AB - sValue2, sTemp are new
IF bCurrentCostDebug THEN Main.WriteDebugLog("[CurrentCost] " & sStr)
' scan message
aScan = Scan(sStr, "*<id>*</id>*<watts>*</watts>*")
' here we have instantaneous data logging
IF aScan.Count = 5 THEN
sValue = aScan[3]
sValue2 = aScan[4] ' AB - this collects rest of string
stemp = (sValue & " " & sValue2) ' AB - add the strings together
EnergyNow = CInt(Left$(sTemp, 5)) + CInt(Mid$(sTemp, 25, 5)) ' AB - parse the strings and add the converted integers
'AB - this calculates EnergyNow seen on CC meter
'Main.WriteLog(("[Current Cost] sValues ") & CStr(EnergyNow))
'AB - above line used for debugging
sAddress = aScan[1]
' try to find device with address, and correct interface type.
iDeviceId = Devices.Find(sAddress, Devices.FindInterface("Current Cost Receiver"))
' if found then update it's value
IF iDeviceId THEN
Devices.ValueUpdate(iDeviceId, "", sValue, "", CStr(Energynow)) ' AB - added EnergyNow to update
sMaxValue = Devices.GetCurrentValueForDevice(iDeviceId, 3)
IF sValue > sMaxValue THEN
Main.WriteLog(("[Current Cost] Max electrical consumption reached ") & sValue & (" Watts"))
Devices.ValueUpdate(iDeviceId, "", "", sValue, "")
END IF
END IF
END IF
aScan = Scan(sStr, "*<h004>*</h004>*")
' here we have real time data
IF aScan.Count = 3 THEN
sValue = aScan[1]
' try to find device with address, and correct interface type.
iDeviceId = Devices.Find(sAddress, Devices.FindInterface("Current Cost Receiver"))
' if found then update it's value
IF iDeviceId THEN Devices.ValueUpdate(iDeviceId, sValue, "", "", "")
END IF
END
- RDNZL
- Forum Moderator
- Posts: 1008
- Joined: Sun Sep 24, 2006 1:45 pm
- Location: Dordrecht, The Netherlands
- Contact:
Re: Domotiga and Envi on USB
A Happy New Year to all of you too.
@Andy I will change the code to parse the xml string with xml parser, this is much more save, thanks for the code...
@Andy I will change the code to parse the xml string with xml parser, this is much more save, thanks for the code...
Regards, Ron.
Re: Domotiga and Envi on USB
Im going to mess around some more, to see if I can understand what the current code does and calculates.
It would be nice to enter the same cost per kWh, entered into the Envi, and perhaps calculate and log what it does. This will need a modified settings dialog and some new variables, database entries etc.
What do you think?
I'm working for the next two weeks, and I fear SQL.... So, it will be a short while before I get around to it..
Thanks,
Andy
It would be nice to enter the same cost per kWh, entered into the Envi, and perhaps calculate and log what it does. This will need a modified settings dialog and some new variables, database entries etc.
What do you think?
I'm working for the next two weeks, and I fear SQL.... So, it will be a short while before I get around to it..
Thanks,
Andy