Inbound data from Internet to Hologram SIM device

Would someone show me an example of how to send inbound data to a SIM device from the Internet?
For an example, lets say I have a SIM device with a web server running on it, or maybe the SIM device is listening on a socket for data. For the first example what would I type into the browser to access the SIM device? From what I have read SpaceBridge might be able to be setup to forward inbound traffic.I just don’t have a clue as to how. I know some but apparently not enough to figure this out.
This application is for use possibly 5 times a day, and maybe exchange less than 1000 bytes per interaction. I must use Cat M1 communication as WiFi is not available where the device is located.

Your help will be greatly appreciated.The online information mostly tells what can be done, but not how to do it. I need a reasonable example to study. Thanks.

Use the SpaceBridge tutorial https://support.hologram.io/hc/en-us/articles/360045634694-Establish-a-secure-Spacebridge-tunnel-to-a-device-using-ssh

You can change the local port and remote port in the section where you specify your linkID. example:

$ssh -p 999 -L localPort:linkidnum:remote port -N -i …

Change local port to any local port you want 40000:linkidnum:42000
You would access your remote device port 42000, like this in a curl transfer.

“curl http://localhost:40000

The above command would issue an http GET command to your remote device port 42000.

To have your browser do the same enter this in the address bar
http://localhost:40000

If you have a web server listening to port 42000 on your device it will receive the get request.

Think of the ssh port forwarding as creating a local port that connects directly to your remote device at the specified port. Once you do that you can send any kind of data you want.

I need to do this without an SSH tunnel. Is that possible?

What is your SIM device?
If it can run python and if you have a http server on another computer I’ve worked out where I can run a python script on the http server from a browser and it basically sends an sms to my SIM device (a Raspberry pi) and it does not use an ssh tunnel. If you think that would help you, I’ll post my code (I’d have to clean it up a bit).

It would be nice to know a little more about how you send something to your SIM device without the SIM device contacting the server first.

My original question was how to send some kind of data from the internet to my SIM device. Since the SIM device is behind a NAT it isn’t directly accessible from the Internet. It is easy to go from the SIM device outgoing to the Internet however.

As it turns out, the Webhook available in the Hologram dashboard makes it fairly easy to send data inbound to the SIM device. What I ended up doing is using the webhook to send a packet to my SIM device. Upon receiving the packet, my device goes outward and connects to the server and I then exchange data as needed. I have also sent the URL to the server I want the device to connect to, in the UDP packet. That way I can choose what server/path to connect to without hard coding it in my program.

I am using an Arduino MKR NB 1500 using the Arduino C++. It was a long struggle, but it is working well now. Thanks for responding with your idea.

I don’t know too much about webhooks.
First a question:
RE: “…the webhook to send a packet to my SIM device.”
Don’t you have to have your sim device somehow connected to the cellular network to be able to receive the webhook?

RE: “It would be nice to know a little more about how you send something to your SIM device without the SIM device contacting the server first.”
I don’t. You had mentioned you need to do it without an SSH tunnel.
I do have my SIM device/Rpi set up a ppp connection:

Python code:
from Hologram.HologramCloud import HologramCloud
hologram=HologramCloud(dict(), network=‘cellular’) #setup hologram cloud
hologram.enableSMS #tell hologram to listen for sms

However I found the ppp connection does not stay connected forever - presumably the cellular carrier closes the connection after a (variable?) amount of time of inactivity.
My solution to this was to have a cronjob run my script every 15 minutes.
I send a sms and the Rpi checks what the message says (in the example below the sms message is “ping”). Then the Rpi runs a script which can include an sms with a topic and data back to the dashboard which could invoke a route/webhook.

I understand how much time you spent solving your problem and I’m glad you got it solved. I’m posting this to share information and perhaps save someone time.

Karl

P.S.
Just in case someone reads this post, here’s a reference and the important part of my python code on my SIM device/R pi:

Reference: Hologram Python SDK - Receiving Data - Hackster.io

Python script that a cronjob runs every 15 minutes:

import datetime
import time
import os
import subprocess
import re

from Hologram.HologramCloud import HologramCloud
hologram=HologramCloud(dict(), network=‘cellular’) #setup hologram cloud
hologram.enableSMS #tell hologram to listen for sms

time.sleep(300) # ample time for Hologram Nova modem to boot

def getsms():
global recv # need to be global if want to reference this outside this function (ie in main section)
recv = hologram.popReceivedSMS()
# print(recv) # if there is no message recv will be: None
# if there is a message recv will be(example): SMS: sender: 447937405250, timestamp: Fri May 27 00:21:50 2022, message: this is a test
if “None” in str(recv):
# print(“no message received”)
pass
else:
print(" ")
print(“Message received: “, recv)
# prepends to log file
# ref: Prepend a line to an existing file in Python - Stack Overflow
filename = ‘/home/karl/Data/logs/log_sms_received.txt’
with open(filename, ‘r’) as original: data = original.read()
now = datetime.datetime.now()
with open(filename, ‘w’) as modified: modified.write(str(recv) + " Cabinpi4 time is: " + now.strftime(” %a %d %b %Y %H:%M:%S %p %Z”) + “\n” + data)
if “ping” in str(recv):
sends_sms_received_ping()

def sends_sms_received_ping():
# will send sms to Hologram dashboard “received ping”
operator=hologram.network.operator
message=operator + " Cabinpi4 received sms ping"
response_code = hologram.sendMessage(message)
print(hologram.getResultString(response_code)) # Prints ‘Message sent successfully’

getsms()

hologram.network.disconnect() # This disconnect the ppp connection if it exists

Thanks for posting your solution. I hope it helps someone.
Your question:

Yes, you have to be connected in the packet switched mode. You are if you are able to send data. SMS only needs to be connected in Circuit Switched mode. You can connect in CS, PS, or both depending on settings. I do both so I can send SMS and data.

The webhook and the hologram API allows you to send data inbound from the internet to your SIM device. I use this to “wake up” my device and then it makes an outbound connection to the server which has always been easy. The SIM devices are behind a NAT so inbound connections don’t work and the webhook they generate allows their server to receive data and pass it to the SIM device. Your ppp connection uses data continuosly to keep the path open. Doing it the way I do uses no data until needed. My application mostly waits and communication is needed only maybe 1-2 times per week although now I am sending data multiple times per day.

The mobile carriers will disconnect you if there is idle time, and there ia a power save mode that causes the cellular modem to go to sleep too. Those are likely to cause your disconnect. My application is mains powered so I shut both of those off and I stay connected to the cellular network. This initialization sequence will do this. It might keep your ppp connection open. Not advised for low power battery operation devices. You only have to do this one time when you start your program.

AT+CFUN=0 # disconnects
AT+CPSMS=0 # turns off power saving mode
AT+CEDRXS=0,4 # disables eDRX, puts modem in periodic sleep mode
AT+CFUN=15 # reboot modem, reconnects

Thanks for the information. I’ll have to digest it and play with it.

Rereading my post above, you may only need to do the above commands one time. After that I think the modem remembers the settings. Post back here if this fixes your problem.