/* DESC: This script can be used to write a received SMS to the serial port. * Copyright (C) 2012 NetModule AG, Switzerland */ DEV = "SERIAL1"; MAXLINES = 100; nb_syslog("sms-to-serial started"); /* check serial port config */ st = nb_config_get("serial.0.status"); if (st != "2") { nb_syslog("Serial port is not enabled for us"); exit(1); } /* check whether SMS daemon is enabled */ st = nb_config_get("smsd.status"); if (st != "1") { nb_syslog("SMS daemon is not enabled"); exit(1); } /* set port attributes first */ ret = nb_serial_setattr(DEV, 115200, 8, 1, 0, 0); if (ret != 0) { printf("Could not set serial attributes for %s\n", DEV); exit(1); } nb_serial_write(DEV, "\r\n"); nb_serial_write(DEV, "sms-to-serial started\r\n"); msgs = nb_sms_list(); nb_syslog("there are %d messages in your SMS inbox\n", length(msgs)); for (i=0; i<length(msgs); i++) { nb_syslog("processing message %d (ID %s, length %d)", i, msgs[i], strlen(msg)); sender = nb_sms_header(msgs[i], "From"); body = nb_sms_body(msgs[i]); if (strlen(sender) > 0 && strlen(body) > 0) { text = sprintf("--- received message from %s ---\r\n%s\r\n---\r\n", sender, body); nb_serial_write(DEV, text); } ret = nb_sms_delete(msgs[i]); if (ret == 0) nb_syslog("deleted message %d\n", i); } exit(0);