Gammu on raspberry Zero

时间:2018-05-23 13:43:40

标签: raspberry-pi

我正在尝试设置一个覆盆子零点以从连接到我实验室的-20°C冰箱的DS18B20探头收集温度。如果检测到温度高于某个值,树莓应发送电子邮件以提醒问题。我使用中国(IEASUN技术)HSUPA调制解调器和Qualcom芯片。 Gammu用于与调制解调器通信。安装gammu和我的脚本后,一切都按预期工作。然后,我决定添加一个功能:在向树莓发送短信时,我希望它发回连接探针的温度(我必须安装gammu-smsd)。这个新功能正在运行,但我的原始警报脚本不再起作用。 我必须强调,这是作为一个autodidact完成的,编码知识最少(这在代码中很明显)。 以下是几个关键信息。

现在,当我运行“警报”脚本时,我收到了以下消息:

Traceback (most recent call last): File "sendsmstemp.py", line 11, in <module> sm.Init() gammu.ERR_DEVICEOPENERROR: {'Text': u'Error opening device. Unknown, busy or no permissions.', 'Code': 2, 'Where': 'Init'}

我的'Alert'脚本的代码是:

import gammu
import sys
    # Create state machine object
    sm = gammu.StateMachine()
    # Read ~/.gammurc
    sm.ReadConfig()
    # Connect to phone
    sm.Init()
import time

while 1:
        tempfile1 = open("/sys/bus/w1/devices/28-031689cf76ff/w1_slave")
        thetext1 = tempfile1.read()
        tempfile1.close()
        tempdata1 = thetext1.split("\n")[1].split(" ")[9]
        temperature1 = float(tempdata1[2:])
        temperature1 = temperature1 / 1000

if temperature1>-10:
      
message1 = {
    'Text': 'Time is:' + time.strftime('%H:%M:%S')+'| Temperature Fridge 1 above -10°C!! . If still above the limit, another sms will be sent in 30min',
    'SMSC': {'Location': 1},
    'Number': '+Myphonenumber',
    'Validity': 'Max',
}
sm.SendSMS(message)

#It waits 30min before sending another sms
time.sleep(1800)

Else:

#test the probe every min
time.sleep(60)

此代码在启动时使用此sh脚本启动:

#!/bin/sh
sleep 10
sudo python /home/pi/smstemp/sendsmstemp.py

我添加到这个覆盆子的最后一个脚本 - 需要安装gammu-smsd软件包 - 显然已经打破了第一个:

#!/bin/sh
from=$SMS_1_NUMBER
message=$SMS_1_TEXT


#ThisHost=$(hostname)

# local file to write into
#FILE=$ThisHost"-status.txt"

# local directory to write to file and pick it for upload
#REPERTOIRE="/home/pi/sendsmstemp/"
#echo $REPERTOIRE$FILE

#Read last temperature 
temperature1=$(find /sys/bus/w1/devices/ -name "28-*6ff" -exec cat {}/w1_slave \; | grep "t=" | awk -F "t=" '{print $2/1000}')

#Send message
reply=""
echo "Temp Fridge 1: $temperature1" | sudo gammu sendsms TEXT "$from"

现在,我的/ etc / gammu-smsdrc配置文件看起来像这样:

    [gammu]
    device = /dev/ttyUSB0
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at
    gammucoding = utf8

    [gammu1]
    device = /dev/ttyUSB1
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at
    gammucoding = utf8

    [gammu2]
    device = /dev/ttyUSB2
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at
    gammucoding = utf8

    [gammu3]
    device = /dev/ttyUSB3
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at
    gammucoding = utf8

    [smsd]
    service = files
    #logfile = syslog
    logfile = /var/spool/gammu/log/gammu-smsdrc.log
    # Change PIN code
    pin = 1234
    RunOnReceive = /home/pi/sendsmstemp/sendinfo.sh

我的/ etc / gammurc配置文件是相同的(除了不包括最后一行)。

gamma-detect命令返回:

    [gammu]
    device = /dev/ttyUSB0
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at

    [gammu1]
    device = /dev/ttyUSB1
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at

    [gammu2]
    device = /dev/ttyUSB2
    name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
    connection = at


[gammu3]
device = /dev/ttyUSB3
name = Phone on USB serial port Qualcomm__Incorporated Qualcomm_CDMA_Technologies_MSM
connection = at

gammu --identify返回:

  Device               : /dev/ttyUSB1
    Manufacturer         : Qualcomm
    Model                : unknown (+CGMM:HSPA MODEM)
    Firmware             : +CGMR:V1.1
    IMEI                 : 356793034431627
    SIM IMSI             : +CIMI:208150010138412

gammu getsecuritystatus返回:

Nothing to enter.

使用此命令按预期工作(它发送短信):

gammu sendsms TEXT 06xxxxxxxx -text "Test"

为什么我的'Alert'脚本没有运行???我迷路了。

非常感谢你的帮助!!

1 个答案:

答案 0 :(得分:0)

正如我对我的问题的评论中所解释的那样,我放弃了。我修改并调试了警报脚本,对于那些可能感兴趣的人(它可以使用2个探针并且很容易添加其他探测器):

#!/usr/bin/env python
# encoding: utf-8
import gammu
import sys

# Create state machine object
sm = gammu.StateMachine()
# Read ~/.gammurc
sm.ReadConfig()
# Connect to phone
sm.Init()

import time


while 1:
    tempfile1 = open('/sys/bus/w1/devices/28-031689cf76ff/w1_slave')
    tempfile2 = open('/sys/bus/w1/devices/28-051691e603ff/w1_slave')
    thetext1 = tempfile1.read()
    thetext2 = tempfile2.read()
    tempfile1.close()
    tempfile2.close()
    tempdata1 = thetext1.split("\n")[1].split(" ")[9]
    tempdata2 = thetext2.split("\n")[1].split(" ")[9]
    temperature1 = float(tempdata1[2:])
    temperature2 = float(tempdata2[2:])
    temperature1 = temperature1 / 1000
    temperature2 = temperature2 / 1000

    if int(temperature1) > -10 or int(temperature2) > -10:
        #Tony
        message = {
        'Text': time.strftime('%H:%M') + '\r\nTemperature of a Team 1 Fridge above -10deg' + '\r\nFridge 1=' + str(temperature1) + 'deg\r\nFridge 2=' + str(temperature2) + 'deg\r\nIf still above the limit, another SMS will be sent in 30 min',
        'SMSC': {'Location': 1},
        'Number': '+336XXXXXXXXX',
        'Validity': 'Max',
        }
        sm.SendSMS(message)
        time.sleep(1800)


        #Check every min
        time.sleep(60)