Skip to content

Instantly share code, notes, and snippets.

@maxmacstn
Created March 7, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxmacstn/72d20419f9febc00e586df69f2c470c6 to your computer and use it in GitHub Desktop.
Save maxmacstn/72d20419f9febc00e586df69f2c470c6 to your computer and use it in GitHub Desktop.
NB-IoT Pre entry climate control
/*
Supported DEVIO NB-DEVKIT I Board
| Do not use PIN |
| 16 TX |
| 17 RX |
| 4 EINT |
| 26 power key |
| 27 reset |
This is an example for DEVIO NB-DEVKIT I. That has get swich data from Magellan IoT Platform for control LED on board.
Please login and enjoy with https://magellan.ais.co.th
*/
#include "Magellan_SIM7020E.h"
#include "ClosedCube_HDC1080.h"
#include <ESP32_Servo.h>
Magellan_SIM7020E magel;
Servo myservo;
ClosedCube_HDC1080 hdc1080;
int servo_up_pos = 90;
int servo_down_pos = 180;
String servo_state;
String servo;
String payload;
const int ledPin = 2; //LED on board Pin 2
const int userButton = 13;
bool toggle = true;
void turnOnPreEntry() {
//Setup servo
myservo.attach(13, 500, 3000);
myservo.write(servo_up_pos);
delay(500);
myservo.write(servo_down_pos); // tell servo to go to position in variable 'pos'
delay(4000);
myservo.write(servo_up_pos); // tell servo to go to position in variable 'pos'
delay(2000);
myservo.detach();
}
void setup()
{
Serial.begin(9600);
magel.begin(); //Init Magellan LIB
payload = "{\"servo\":0}"; //Please provide payload with json format
magel.report(payload); //Initial switch data to Magellan
pinMode(ledPin, OUTPUT);
//Setup temperature sensor
// Default settings:
// - Heater off
// - 14 bit Temperature and Humidity Measurement Resolutions
hdc1080.begin(0x40);
Serial.print("Manufacturer ID=0x");
Serial.println(hdc1080.readManufacturerId(), HEX); // 0x5449 ID of Texas Instruments
Serial.print("Device ID=0x");
Serial.println(hdc1080.readDeviceId(), HEX); // 0x1050 ID of the device
//Setup servo
myservo.attach(13, 500, 3000);
myservo.write(servo_up_pos);
myservo.detach();
delay(500);
}
void loop()
{
/*
Example get swich data from Magellan IoT platform for control LED on board
*/
servo_state = magel.getControl("servo"); //Get switch data from Magellan IoT platform
if (servo_state.indexOf("40300") == -1) //Response data is not 40300
{
if (servo_state == "1") {
payload = "{\"servo\":1}"; //Please provide payload with json format
magel.report(payload); //Initial switch data to Magellan
delay(1000);
turnOnPreEntry();
payload = "{\"servo\":0}"; //Please provide payload with json format
magel.report(payload); //Initial switch data to Magellan
delay(5000);
}
}
String temperature = String(hdc1080.readTemperature());
String humidity = String(hdc1080.readHumidity());
payload = "{\"temperature\":" + temperature + ",\"humidity\":" + humidity + ",\"servo\":0}"; //Please provide payload with json format
magel.report(payload); //Report Userbutton state
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment