Receiving SMS via Phone Number


#1

Hello, just got a Nova and jumped right in, but there’s a … bit of a learning curve.

I’ve browsed through a bunch of community projects and the docs but wasn’t able to find the right info relating to receiving an SMS to a Hologram assigned phone number. I am able to receive SMS’s sent via the Cloud/Dashboard and can send from my RasPi with the Hologram python script to my personal phone number.

However, when attempting to send an SMS to the Hologram provided number from that phone is where I’m stalled. I assume there needs to be a running server on the RPi to process the inbound SMS, but that’s where I’m lost. I tried this, but the script doesn’t seem to work (syntax errors, trying to work through it)

Any nudge in the right direction would be extremely helpful. Something as simple as forwarding a received SMS at the Hologram number to my mobile phone, or via email would be a great starting point, just to figure this thing out. For instance, I tried to create an SMS and Email route with no success, as I’m clearly missing something.

Apologies for asking a dumb question that is probably described elsewhere. Thanks in advance for helping a noob out :blush:


#2

Hey Ian
I can send a sample script that I’m using - I think I posted my code in another topic somewhere here.

I do the receiving on a Pi - All I use is an infinite while loop in a Python script.
It sleeps for 5 seconds or so then checks and clears the received queue to process
and respond to any incoming messages

I don’t use the Nova to send because I wanted the possibility of responding back with an MMS, but it might be enough to get you started.

Don


#3

I modified one of mine to see if you could send as well as receive

Try it out and let me know - here’s a gist file


#4

Here is a short script I wrote to send and receive SMS messages (and data messages) using events, taking in MQTT messages as the source.

import time
import paho.mqtt.client as mqtt
from Hologram.HologramCloud import HologramCloud
import sys

credentials = {'devicekey': '********'}
hologram = HologramCloud(credentials, network='cellular', authentication_type='csrpsk')

Broker = "localhost"
sub_topic_data = "hologram/outbound/data"
pub_topic_data = "hologram/inbound/data"
sub_topic_sms = "hologram/outbound/sms"
pub_topic_sms = "hologram/inbound/sms"
destination_number = "+1NNNNNNNNNN"

# when connecting to mqtt do this;
def on_connect(node, userdata, flags, rc):
    print "Connected with result code "+str(rc)
    client.subscribe(sub_topic_data)
    client.subscribe(sub_topic_sms)

# when receiving a mqtt message do this;
def on_message(node, userdata, msg):
    message = str(msg.payload)
    print msg.topic+" "+message
    if msg.topic == sub_topic_data:
       response = hologram.sendMessage(message, topics=[msg.topic, sub_topic_data])
       print hologram.getResultString(response)
    elif msg.topic == sub_topic_sms:
       response = hologram.sendSMS(destination_number, message)
       print hologram.getResultString(response)
    else:
       print "Invalid message topic received"

def sayHelloReceivedAndPopMessage():
  print "hello! I received an cloud message (via event)!"
  recv = hologram.popReceivedMessage()
  if recv is not None:
     print recv
     client.publish(pub_topic_data, recv)
  else:
    recv = hologram.popReceivedMessage()
    if recv is not None:
      print recv
      client.publish(pub_topic_data, recv)


def sayHelloReceivedSMSAndPopMessage():
  print "hello! I received an SMS message (via event)!"
  recv = hologram.popReceivedSMS()
  if recv is not None:
     print recv.message
     client.publish(pub_topic_sms, recv.message)

client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect(Broker, 1883, 60)
client.loop_start()

hologram.event.subscribe('sms.received', sayHelloReceivedSMSAndPopMessage)
print 'subscribed to receive SMS message events'
hologram.event.subscribe('message.received', sayHelloReceivedAndPopMessage)
print 'subscribed to receive cloud message events'
hologram.openReceiveSocket()
print ('Ready to receive data...')
recv = hologram.popReceivedMessage()

try:
    while True:
        hologram.enableSMS();
        time.sleep(10)

except KeyboardInterrupt as e:
    print 'Closing socket...'
    hologram.closeReceiveSocket()

    if not hologram.network.at_sockets_available:
        hologram.network.disconnect()

    sys.exit(e)

#5

Wow, thank you both immensely!

These are both exactly what I had been stuck on trying to find. Will look into both of them this weekend, but quickly scanning the code it seems like they’ll be an awesome starting point. Cheers!


#6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.