Keenan Johnson
Published

AVR-IoT Cellular Mini

A guide for getting started with the AVR-IoT Cellular Mini.

BeginnerProtip1 hour1,270
AVR-IoT Cellular Mini

Things used in this project

Hardware components

AVR IoT Mini Cellular Board
Microchip AVR IoT Mini Cellular Board
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Example HTTP Application

C/C++
#include <Arduino.h>
#include <http_client.h>
#include <lte.h>
#include <sequans_controller.h>
#include <log.h>
#include <led_ctrl.h>
 
#define TIMEZONE_URL "worldtimeapi.org"
#define TIMEZONE_URI "/api/timezone/Europe/Oslo.txt"
 
long getTimeFromApiresp(String *resp)
{
	int unixTimeIndex = resp->indexOf(String("unixtime: "));
	int utx_datetimeIndex = resp->indexOf(String("utc_datetime"));
 
	String substr = resp->substring(unixTimeIndex + 10, utx_datetimeIndex - 1);
	return substr.toInt();
}
 
void setup()
{
	// Start up the LEDs
	LedCtrl.begin();
	LedCtrl.startupCycle();
  
	Log.begin(115200);
	Log.info("Starting HTTP Get Time Example");
 
	// Start LTE modem and connect to the operator
	Lte.begin();
 
	if (!HttpClient.configure(TIMEZONE_URL, 80, false))
	{
		Log.errorf("Failed to configure the http client for the domain %s\r\n", TIMEZONE_URL);
		return;
	}
 
	Log.info("Configured to HTTP");
 
	HttpResponse response;
	response = HttpClient.get(TIMEZONE_URI);
	if (response.status_code != HttpClient.STATUS_OK)
	{
		Log.errorf("Error when performing a GET request on %s%s. Got status code = %d. Exiting...\r\n", TIMEZONE_URL, TIMEZONE_URI, response.status_code);
		return;
	}
 
	Log.infof("Successfully performed GET request. Status Code = %d, Size = %d\r\n", response.status_code, response.data_size);
 
	String body = HttpClient.readBody(512);
 
	if (body == "")
	{
		Log.error("The returned body from the GET request is empty. Something went wrong. Exiting...");
		return;
	}
 
	Log.infof("Got the time (unixtime) %lu\r\n", getTimeFromApiresp(&body));
}
 
void loop()
{
	while (1) {}
}

Credits

Keenan Johnson

Keenan Johnson

5 projects • 24 followers
Building @ribbitnetwork. Writing (see bio link). 🚀engineer turned to Climate. Startup Founder. Consultant. Maker. he/him/his

Comments