diff --git a/examples/AT-bridge_serial2/AT-bridge_serial2.ino b/examples/AT-bridge_hardware_serial/AT-bridge_hardware_serial.ino similarity index 100% rename from examples/AT-bridge_serial2/AT-bridge_serial2.ino rename to examples/AT-bridge_hardware_serial/AT-bridge_hardware_serial.ino index f480153..29425c8 100644 --- a/examples/AT-bridge_serial2/AT-bridge_serial2.ino +++ b/examples/AT-bridge_hardware_serial/AT-bridge_hardware_serial.ino @@ -8,9 +8,9 @@ void setup() { Serial.begin(57600); Serial2.begin(9600); + Serial.println("Chiang Mai Maker Club's AT-Bridge engine is started."); Bridge.init(&Serial, &Serial2); - } void loop() diff --git a/examples/AT-bridge_uno/AT-bridge_uno.ino b/examples/AT-bridge_uno/AT-bridge_uno.ino new file mode 100644 index 0000000..988a15b --- /dev/null +++ b/examples/AT-bridge_uno/AT-bridge_uno.ino @@ -0,0 +1,21 @@ +#include +#include +#include + +CMMC_NB_IoT nb; +CMMC_AT_Bridge &Bridge = nb.Bridge; +AltSoftSerial altsoftSerial; + +void setup() +{ + Serial.begin(57600); + altsoftSerial.begin(9600); + + Serial.println("Chiang Mai Maker Club's AT-Bridge engine is started."); + Bridge.init(&Serial, &altsoftSerial); +} + +void loop() +{ + Bridge.loop(); +} \ No newline at end of file diff --git a/examples/altsoftserial_example/altsoftserial_example.ino b/examples/altsoftserial_example/altsoftserial_example.ino deleted file mode 100644 index eebe2c4..0000000 --- a/examples/altsoftserial_example/altsoftserial_example.ino +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include -#include - -AltSoftSerial nbSerial; -CMMC_NB_IoT nb(&nbSerial); -#define NB_PWR_PIN 15 - -void setup() -{ - pinMode(NB_PWR_PIN, OUTPUT); - digitalWrite(NB_PWR_PIN, HIGH); - Serial.begin(57600); - Serial.setTimeout(4); - - nbSerial.begin(9600); - nbSerial.setTimeout(6); - - delay(10); - while (!Serial) { - ; // wait for serial port to connect. Needed for native USB - } - Serial.println(); - Serial.println(F("Starting application...")); - - nb.onDeviceReboot([]() { - Serial.println(F("[user] Device being rebooted.")); - }); - - nb.onDeviceReady([](CMMC_NB_IoT::DeviceInfo device) { - Serial.println("[user] Device Ready!"); - Serial.print(F("# Module IMEI--> ")); - Serial.println(device.imei); - Serial.print(F("# Firmware ver--> ")); - Serial.println(device.firmware); - Serial.print(F("# IMSI SIM--> ")); - Serial.println(device.imsi); - }); - - nb.onConnecting([]() { - Serial.println("[user] Connecting to NB-IoT Network..."); - delay(1000); - }); - - nb.onConnected([]() { - Serial.println("[user] NB-IoT Network connected"); - }); - - nb.begin(); -} - -void loop() -{ - -} \ No newline at end of file diff --git a/examples/hwserial_example/hwserial_example.ino b/examples/hwserial_example/hwserial_example.ino index 7eb7811..f036054 100644 --- a/examples/hwserial_example/hwserial_example.ino +++ b/examples/hwserial_example/hwserial_example.ino @@ -43,22 +43,6 @@ void setup() nb.onConnected([]() { Serial.println("[user] NB-IoT Network connected"); - char tmp[400]; - nb._writeCommand(F("AT+CSQ"), 10L, tmp); // imsi sim - String t = String(tmp); - t.replace("OK", " - OK"); - Serial.println(t); - int ct = 1; - int sockId = nb.createUdpSocket("159.89.205.216", 11221, UDPConfig::DISABLE_RECV); - nb.createUdpSocket("159.89.205.216", 11222, UDPConfig::DISABLE_RECV); - String _tmp = ""; - // while(1) { - // _tmp += String(ct) + "-"; - // Serial.println(String("payload size = ") + _tmp.length()) + String("byte"); - // nb.sendMessage(_tmp); - // delay(2000); - // ct++; - // } }); nb.begin(); diff --git a/examples/softserial_example/softserial_example.ino b/examples/softserial_example/softserial_example.ino deleted file mode 100644 index 6a731db..0000000 --- a/examples/softserial_example/softserial_example.ino +++ /dev/null @@ -1,127 +0,0 @@ -#define DEBUG_BUFFER_SIZE 1000 - -#include -#include "ESP8266WiFi.h" -#include -#include -#include -#include - -#define RX 14 -#define TX 12 -static SoftwareSerial modemSerial(RX, TX, false, 128); - -const uint8_t PROJECT = 1; -const uint8_t VERSION = 1; - -uint8_t header[2] = {0xfd, 0xfa}; -uint8_t tail[2] = {0x0d, 0x0a}; - -static CMMC_Packet packet(PROJECT, VERSION, header, tail); -static CMMC_NB_IoT nb(&modemSerial); -static CMMC_LED led(2, LOW); -static CMMC_LED shield(15, HIGH); - -extern "C" { -#include "user_interface.h" -} - -void setup(){ - WiFi.disconnect(); - WiFi.mode(WIFI_OFF); - WiFi.forceSleepBegin(); - - Serial.begin(57600); - modemSerial.begin(9600); - delay(100); - - Serial.println(F("......")); - - led.init(); - shield.init(); - - Serial.println(ESP.getCpuFreqMHz()); - Serial.println(modemSerial.baudRate()); - - Serial.setTimeout(4); - modemSerial.setTimeout(8); - - - - delay(50); - Serial.println(); - Serial.println(F("Starting application...")); - - while(!modemSerial) { - Serial.println("wait modem serial.."); - delay(10); - } - - nb.onDeviceReboot([]() { - Serial.println(F("[user] Device being rebooted.")); - }); - - nb.onDeviceReady([](CMMC_NB_IoT::DeviceInfo device) { - led.high(); - Serial.println("[user] Device Ready!"); - Serial.print(F("# Module IMEI--> ")); - Serial.println(device.imei); - Serial.print(F("# Firmware ver--> ")); - Serial.println(device.firmware); - Serial.print(F("# IMSI SIM--> ")); - Serial.println(device.imsi); - }); - - nb.onConnecting([]() { - Serial.println("[user] Connecting to NB-IoT Network..."); - led.toggle(); - delay(1000); - }); - - nb.onConnected([=]() { - Serial.println("[user] NB-IoT Network connected"); - uint32_t ct = 1; - String _tmp = ""; - int sockId = nb.createUdpSocket("159.89.205.216", 11221, UDPConfig::DISABLE_RECV); - delay(100); - while(1) { - packet.setField(1, 0x11); - packet.setField(2, 0x22); - packet.setField(3, 0x33); - packet.setField(4, 0x44); - packet.setField(5, 0x55); - packet.setField(6, 0x66); - packet.setSensorBattery(analogRead(A0)); - packet.setSensorName("LATTE-0x10"); - CMMC_PACKET_T *p = packet.getRawPacket(); - uint32_t nextTick = millis() + 2000; - - Serial.printf("sending result: %d\r", nb.sendMessage((uint8_t*)p, packet.size())); - - int runCnt = 0; - while(runCnt++ < 65) { - led.toggle(); - delay(100); - if (millis() > nextTick) { - Serial.println("Sending..."); - while(!nb.sendMessage((uint8_t*)p, packet.size())) { - delay(100); - } - nextTick += 2000; - } - } - Serial.println("BYE.."); - delay(1000); - led.high(); - shield.low(); - ESP.deepSleep(20e6, WAKE_RF_DISABLED); - } - }); - - nb.begin(); -} - -void loop() -{ - -} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index f4ac3ee..e4ca923 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,27 +8,27 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html -; [env:CMMC_NB_IoT_app_uno] -; board = uno -; platform = atmelavr -; framework = arduino -; lib_deps = -; AltSoftSerial -; extra_scripts = extra_script.py - -[env:CMMC_NB_IoT_app_mega] -board = megaatmega2560 +[env:CMMC_NB_IoT_app_uno] +board = uno platform = atmelavr framework = arduino lib_deps = AltSoftSerial extra_scripts = extra_script.py +; [env:CMMC_NB_IoT_app_mega] +; board = megaatmega2560 +; platform = atmelavr +; framework = arduino +; lib_deps = +; AltSoftSerial +; extra_scripts = extra_script.py + [platformio] ; src_dir = examples/altsoftserial_example ; src_dir = examples/softserial_example # src_dir = examples/softserial_example ; src_dir = examples/hwserial_example -src_dir = examples/AT-bridge_serial2 +src_dir = examples/AT-bridge_uno lib_dir = .src-dev \ No newline at end of file