EasyManuals Logo
Home>Digi>Modem>XBee 3

Digi XBee 3 User Manual

Digi XBee 3
293 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #41 background imageLoading...
Page #41 background image
Get started with MicroPython Example: code a request help button
Digi XBe 3 Cellular LTE Cat 1 AT&T Smart Modem User Guide
41
Send a text (SMS) when the button is pressed
After creating a while loop that checks for a button press, add sending an SMS to your code. Instead of
printing Button pressed! to the screen, this code sends Button pressed to a cell phone as a text
(SMS) message.
To accomplish this, use the sms_send() method, which sends a string to a given phone number. It
takes the arguments in the following order:
1. <phone number>
2. <message-to-be-sent>
Before you run this part of the example, you must create a variable that holds the phone number of
the cell phone or mobile device you want to receive the SMS.
1. To do this, at the MicroPython >>> prompt, type the following command, replacing 1123456789
with the full phone number (no dashes, spaces, or other symbols) and press Enter:
ph = 1123456789
2. After you create this ph variable with your phone number, copy the code below and enter it
into MicroPython using paste mode (Ctrl+E) and then run it.
from machine import Pin
import network # Import network module
import time
c = network.Cellular() # initialize cellular network parameter
dio0 = Pin("D0", Pin.IN, Pin.PULL_UP)
while not c.isconnected(): # While no network connection.
print("Waiting for connection to cell network...")
time.sleep(5)
print("Connected.")
# Give feedback to inform user a button press is needed.
print("Waiting for SW2 press...")
while (True):
if (dio0.value() == 0):
# When SW2 is pressed, the module will send an SMS
# message saying "Button pressed" to the given target cell phone
number.
try:
c.sms_send(ph, 'Button Pressed')
print("Sent SMS successfully.")
except OSError:
print("ERROR- failed to send SMS.")
# Exit the WHILE loop.
break
Note You can easily copy and paste code from the online version of this guide. Use caution with the
PDF version, as it may not maintain essential indentations.
Note If you have problems pasting the code, see Syntax error at line 1. For SMS failures, see Error
Failed to send SMS.

Table of Contents

Other manuals for Digi XBee 3

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Digi XBee 3 and is the answer not in the manual?

Digi XBee 3 Specifications

General IconGeneral
BrandDigi
ModelXBee 3
CategoryModem
LanguageEnglish

Related product manuals