#VSCP: New client id assignment

From version 13.1.1.4 a new more deterministic way is used to generate automatic client id’s. VSCP daemon internal events will use id’s from the high part of the client id that will always be the same.

Client id’s for drivers and other configuration parts that before was generated from the order the item was loaded  also now work that way If the client id part of a GUID is zero (byte 12/13). If however it is not AND the client id is not already used in the system the VSCP daemon will use the set client id for the item.

This means that drivers with set GUID’s will always have the same interface GUID being more deterministic. tcp/op connections, websocket connections rest i/f connections will be assigned client id’s on the go as before.

It is recommended to use the Ethernet/IP GUID series as a basis for interfaces.

HowTo: SMS Alarms

The problem

Just last week a house burned down to the ground here in my hometown. The family of two adults and three kids just made it out. This reminded me of the importance of alarms. My family as any family I guess have had some incidents over the year. In our case with a four floor building, cellar, office, apartment where we live and the attic it can be hard to, despite alarm equipment, to recognize what is happening in the cellar when your are in the apartment watching a film or even worse, sleeping. We have had our incident over the years as most people do.

I use VSCP here of course. This system is intelligent enough to close down functionality  when things get bad. But a few weeks ago I had a bad incident. I have a VSCP node that control the water boiler in the cellar for warm water. This is a very simple setup. A relay, a sensor and a control node. I can thus remotely control sense and control the temperature of the hot water in the house.

Sitting in the office I noticed a strange sound. I usually play music loud so it had been going on for some time I guess. I went around the house investigating the sound and when I came down to the cellar I heard that the boiler literally boiled hard. Not a good thing. There is a risk for a steam explosion from this so I got really worried.

I turned of the power. Opened valves for hot water in the office and got steam and boiling water coming out. I checked the control unit and it had turned of the relay. Still the temperature was way over the limit. There is an independent security unit inside the boiler that should turn off power when it get over a certain temperature. Apparently this mechanism had not done it’s job. Also the security valve that prevent to hot water from going out in the system also malfunctioned otherwise I should not have got steam hot water out of the office valve. Two faults. The pressure security mechanism on the other side worked. But the boiler never got up to the 10 bar needed to release it. So things were actually not to bad. Bit could gone worse if I had been away for example.

I later checked the cause and detected that the relays had gone stuck in the on position.  Something that happen to relays some times when load is heavy or control is a bit jumpy.  I also tested the overheat protection and it worked as it should, probably it would have just needed a bit more time to cut the power. The blender protecting the water line from to hot water was the only faulty component. Still this was a bit scary. I need to be alarmed if this happen again.

GSM Modem

I previously sold professional GPRS modems in the FrogShop from Caimore. Still have some around so I decided to put one to work. You can find may similar on Aliexpress or ebay. and even lower cost modules intended for Arduino or similar as the one below. They all have there pros and cons.

SIM Card

Next thing is to find a SIM card. In Sweden this is not a simple thing if you just want a module that sends a few SMS’s per year. The solutions available are highly overpriced. I know there are other and better options available in other countries. I just select a cash card to get started.

Software

Initially I thought about writing a driver for the VSCP daemon and this may still be an option, we will see. I have for a long time used Smstools a wonderful package for uses like this. With the help of the decision matrix of the VSCP daemon it will be possible to do plenty without a driver. So this is the solution I go for.

There is a nice getting started tutorial for smstools here. Thus no need for me to write one again.

The only thing i ned to do to get things working is to set the device and the baudrate lines in /etc/smsd.conf file

device = /dev/ttyUSB0

as I use an USB adapter for serial communication.

And

baudrate = 115200

as i use that higher speed.

Then I just restart the smsd daemon with

sudo service smsd restart

and everything is working.

Sending SMS’s

We are just interested in sending SMS’s here so we stick to that. But receiving SMS’s (we look at that in a later post) is also equally simple.

To send a SMS one just copy a formated file into the folder /var/spool/smsd/outgoing. So to send an SMS to +467012345678 one send a file

To: 467012345678

ALARM: The water in the boiler is way to hot!

Write this to a file and copy it to /var/spool/smsd/outgoing and the SMS will be delivered to the set recipient.

You can set the header to

To: 467012345678
Flash: yes

ALARM: The water in the boiler is way to hot!

to send a flash SMS (is displayed on the users screen directly but not saved). It can hardly be simpler.

Voicecall

Another possibility is to make a call to a receiver instead. Add Voicecall to the header like this

To: 46730533146
Voicecall: yes

TONE: 5 #,#,#

Here the mentioned precipitant will receive a call and when answered five groups of three “#” DTMF tons will be sounded. Tones that can be used to tell the recipient about the cause of the alarm. I will for instance use the number of “#” sounds as an indication of what floor the alarm happened. Possible with different tones for different alarms.

vscpd and smstools

So now lets put this to work for our VSCP based system.

Alarm related events is collected in the class CLASS1.ALARM. The CLASS1.ALARM, Type=2, Alarm occurred is intended for alarm conditions.  So if we let sensors that generate alarms send this event and trigger on it in the decision matrix of the VSCP daemon we can send our SMS and voicecalls from there. The zone and subzone can be used as markers for where the alarm occurred. The originating GUID can also be used to identify this.

<row enable="true" groupid="alarm" >

	<comment>Send alarm.</comment>
	
	<mask priority="0" class="65535" type="65535" guid="00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" >
	</mask>
	
	<filter priority="0" class="1" type="2" guid="00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00" > 
	</filter>
	
	<action>0x10</action>
	<param >/home/vscp/doalarm.py %zone %subzone event.guid %isodate %isotime "Current boiler temp is %vardecode:[boiler-temp]"</param>
	
	<allowed_from>0000-01-01 00:00:00</allowed_from>
	<allowed_to>9999-12-31 23:59:59</allowed_to>
	<allowed_weekdays>mtwtfss</allowed_weekdays>
	<allowed_time>*-*-* *:*:*</allowed_time>
</row>

So what do we have here?

We trigger on any alarm occurred event regardless of priority and from which originating GUID (which unit) it comes from. It would have been possible to do several DM rows for different GUID’s (originating nodes) of course to handle alarms from them different.

The time block (form <allowed from> to the end) just say that this can happen anytime. Leaving this block out has the same meaning.

And last the important action.  In this case, execute external program (0x10) and in the parameter for the action the actual program to execute is specified with the path to it (/home/vscp/doalarm.py) is given. The rest of the action parameter line is arguments to this external program.

  • %event.zone – Zone for alarm event.
  • %event.subzone – Subzone for alarm event.
  • %event.guid – GUID for alarm event.
  • %isodate – Date on ISO format for alarm.
  • %isotime – Time on ISO format for alarm.
  • %vardecode:[//alarmtext//] – Specific text for alarm.

The description of the decision matrix is here.

Zone and subzone is numericals that can be used to specify the place and equipment that generated the alarm. I have floor plan in zone and a room on that floor plan in subzone.

The vardecode writes out the content of the given variable if it is present. We will come back to it later.

When this row is added the external script will be executed when CLASS1.ALARM, TYPE=2 is generated by a node and received by the VSCP daemon.

It is good if the script can do both voice calls and SMS sends and that both can be sent to a list of numbers.

The doalarm.py script

import sys
import uuid

filename_voice = str(uuid.uuid4())
filename_sms = str(uuid.uuid4())

# Dir that holds outgoing SMS messages
OUTDIR="/var/spool/sms/outgoing"

# Voicel recipients (comma separated list, empty for non)
VOICE_RECEIVERS="4673xxxxxxxx,4676yyyyyyyyy"

# Set to true for flash SMS
bflash = False

# SMS recipients (comma eparated list, empty for non )
#SMS_RECEIVERS="4673xxxxxxxx,4676yyyyyyyyy"
SMS_RECEIVERS=""

SMS_TEXT="An alarm condition has occured!"

# -----------------------------------------------------------------------------

voicetone="5 "
for x in range(0, int( sys.argv[1] ) ):
	voicetone = voicetone + "1,"

voiceRcvList = VOICE_RECEIVERS.split(",")

cnt=0
if VOICE_RECEIVERS != "" :
	for receiver in voiceRcvList:
		print( OUTDIR + "/" + filename_voice + str(cnt) )
		with open( OUTDIR + "/" + filename_voice + str(cnt), "w") as text_file:
			text_file.write( "To: {0}\n".format(receiver) )
			text_file.write( "Voicecall: yes\n\n" )
			text_file.write( voicetone )
		cnt = cnt + 1

SMSRcvList = SMS_RECEIVERS.split(",")

if SMS_RECEIVERS != "" :
	for receiver in SMSRcvList:
		print( OUTDIR + "/" + filename_voice + str(cnt) )
		with open( OUTDIR + "/" + filename_voice + str(cnt), "w") as text_file:
			text_file.write( "To: {0}\n".format(receiver) )
			if bflash:
				text_file.write( "Flash: yes\n" )
			text_file.write( "\n\n" )
			text_file.write( SMS_TEXT+"\n" )
			text_file.write( "Zone={0} SubZone={1} Time={2} Date={3}\n".format(sys.argv[1],sys.argv[2],sys.argv[3],sys.argv[4] ) )
			text_file.write( "{0}".format(sys.argv[5]) )        
		cnt = cnt + 1

This is the script. It is written i Python to make things simple to edit and/or change. You can find the script in the VSCP repository.

Just edit the variables in the beginning of the script to fit your setup and you are set to go.

Note that the voice call will do five groups of a series of “1”-press DTMF where the count is the same as the supplied zone parameter. In my case this is the floor plan so I know instantly where something happened and runa way and fix it. The SMS also give me more info.

The variable

To come back to the variable that is sent as a parameter. Perfect is to save a  measurement value in another part of the DM. Like this

<row enable="true" groupid="temperature" >
    <mask priority="0" class="65535" type="65535" GUID="FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF" > </mask>
    <filter priority="0" class="10" type="6" GUID="FF:FF:FF:FF:FF:FF:FF:FF:3C:00:08:01:92:9D:3D:10" > </filter>
    <action>80</action>
    <param>boiler-temp;float;true;0;0x777;%measurement.float</param>
    <comment>Store boiler temperature in variable</comment>
    <allowed_from>0000-01-01 00:00:00</allowed_from>
    <allowed_to>9999-12-31 23:59:59</allowed_to>
    <allowed_weekdays>mtwtfss</allowed_weekdays>
    <allowed_time>*-*-* *:*:*</allowed_time>
</row>

An alternative way to do it

Another way is to do measurement compares, as in this case check the boiler temperature, you can read more about this method here and it is in many ways the same as the one we described above but more specific for boiler temp alarm.

And next?

Now you should be able to add your own alarms to your VSCP setup. Maybe something that will do good work in your remote cottage, alarming  freezing conditions before bad and costly things happens. In my house we will now sleep much better knowing that we will get alarms when things go wrong.

I promised to continue with a follow up on how to react on incoming SMS mesages. This makes it possible to remotely control things as well such as turning on the heat in that remote cottage I mentioned above. I will try to write that story up soon. Time is my enemy, or rather lack of it.

Cheers
/Ake