Things used in this project

Hardware components:
Compare particleelectron
Particle Electron
×1
Software apps and online services:
Zpm toolbar 1
Zerynth Studio

Schematics

Particle Electron - Pinmap
Electron big wbfbhl1gca

Code

Zerynth - HTTP Time GSM ExamplePython
################################################################################
#
# HTTP Time GSM Example
#
################################################################################
 
# the classic wifi requests example, very little changes accessing
# the net through a gsm connection!
 
# import our gsm chip specific driver
from ublox.g350 import g350
# and the generic gsm module
from wireless import gsm
import streams
import requests
 
 
streams.serial()
 
# init the gsm driver!
# The driver automatically registers itself to the gsm interface
# with the correct configuration for the selected board
g350.auto_init()
print("Connecting...")
try:
    # connect to our APN
    gsm.connect_net('spark.telefonica.com')
except Exception as e:
    print("ooops, something wrong while connecting :(", e)
    while True:
        sleep(1000)
 
# from now on everything is exactly identical to wifi HTTP Time Example ;)
 
# let's try to connect to timeapi.org to get the current UTC time
for i in range(3):
    try:
        print("Trying to connect...")
        # we need to impersonate a web browser: as easy as setting the http user-agent header
        user_agent = {"user-agent":"Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"}
        # go get that time!
        # url resolution and http protocol handling are hidden inside the requests module
        response = requests.get("http://www.timeapi.org/utc/now",headers=user_agent)
        # let's check the http response status: if different than 200, something went wrong
        print("Http Status:",response.status)
        # if we get here, there has been no exception, exit the loop
        break
    except Exception as e:
        print(e)
 
 
try:
    # check status and print the result
    if response.status==200:
        print("Success!!")
        print("-------------")
        print("And the result is:",response.content)
        print("-------------")
except Exception as e:
    print("ooops, something very wrong! :(",e)

Credits

Photo
Luigi Francesco Cerfeda

Yet another Tony Stark wannabe

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

What's My I2C Address?
Easy
  • 69
  • 3

The story of how to make a clock through using a LCD 1602 or LCD 2004 over I2C.

MyHumidity Controlled by BME280 and Photon
Easy
  • 181
  • 4

Full instructions

Checks if humidity threshold is reached and informs the user by using Blynk/IFTTT-services with softAP integration.

Tweeting Particle Photon
Easy
  • 42
  • 1

Full instructions

Tweet your friends with only the press of a button!

MyLight-Clock with NeoPixel Ring 12 Controlled by Photon
Easy
  • 259
  • 2

Full instructions

Read the time at night? Without glasses? Impossible? Focus on 2 light points, which will tell you the hour and the minute.

Map Your Particles!
Easy
  • 1,354
  • 20

Protip

Locate your Particle Photons, P1s and Electrons on a map without needing extra hardware. Use Ubidots or an offline map alternative

BME280 measures and displays on OLED controlled by Photon
Easy
  • 340
  • 2

Protip

I share my first steps with the sensor BME280 (temp / humi / pressure / altitude) and an OLED 128 * 64 px

Add projectSign up / Login