Here is the current "work in progress" rough draft of the Arduino UNO sketch for this demo / test.
Please free free to improve to code and repost your improvements back and use as you wish, free as a bird.
Code:
/*
Arduino Project: iPhone to HM-10 BLE to NB-IoT Shield to NB-IoT Network to Internet to Linux Server
Work in Progress by Neo version 0.01 Jan 2020
Currently does not receive data from UDP server when doBLE() is active
Comments welcome.
*/
#include <SoftwareSerial.h>
#include <ArduinoBlue.h>
#include "AIS_NB_BC95.h"
#define NBIOT true
#define BLE true
#define DEBUG2 true
#define ENABLE_BLE_IN_LOOP true
#define ENABLE_NBIOT_PING false
String apnName = "ble.nms";
String serverIP = "YOUR.IP.ADDR.HERE"; // Your Server IP
String serverPort = "YOUR_PORT"; // Your Server Port
String udpData = apnName;
AIS_NB_BC95 AISnb;
const long interval = 20000; //millisecond
unsigned long previousMillis = 0;
long cnt = 0;
const unsigned long BAUD_RATE = 9600;
// The bluetooth tx and rx pins must be supported by software serial.
// Visit https://www.arduino.cc/en/Reference/SoftwareSerial for unsupported pins.
// Bluetooth TX -> Arduino UNO D3 was D8
const int BLUETOOTH_TX = 3;
// Bluetooth RX -> Arduino UNO D4 was D7
const int BLUETOOTH_RX = 2;
int prevThrottle = 49;
int prevSteering = 49;
int throttle, steering, sliderVal, button, sliderId;
SoftwareSerial bluetooth(BLUETOOTH_TX, BLUETOOTH_RX);
ArduinoBlue phone(bluetooth); // pass reference of bluetooth object to ArduinoBlue constructor
void setup()
{
// Start serial communications.
// The baud rate must be the same for both the serial and the bluetooth.
Serial.begin(BAUD_RATE);
if (BLE)
{
if (NBIOT)
{
delay(10000);
}
bluetooth.begin(BAUD_RATE);
delay(100);
Serial.println("arduino ble setup complete\n");
phone.sendMessage("Arduino setup complete");
}
if (NBIOT)
{
AISnb.debug = true;
if (DEBUG2)
Serial.println("NBIOT SETUP START\n");
AISnb.setupDevice(serverPort);
if (DEBUG2)
Serial.println("NBIOT SETUP GET DEVICE IP\n");
String ip1 = AISnb.getDeviceIP();
delay(1000);
if (DEBUG2)
Serial.println("NBIOT SETUP GET DEVICE IP\n");
pingRESP pingR = AISnb.pingIP(serverIP);
previousMillis = millis();
if (DEBUG2)
Serial.println("NBIOT SETUP COMPLETE\n");
if (BLE)
{
phone.sendMessage("NBIOT Setup Complete");
}
}
}
// Put your main code here, to run repeatedly:
void loop()
{
if (BLE and ENABLE_BLE_IN_LOOP)
{
doBLE();
}
if (NBIOT)
{
doNBIOT();
}
}
void doBLE()
{
// ID of the button pressed pressed.
button = phone.getButton();
String msg = "";
// Returns the text data sent from the phone.
// After it returns the latest data, empty string "" is sent in subsequent.
// calls until text data is sent again.
String str = phone.getText();
// Throttle and steering values go from 0 to 99.
// When throttle and steering values are at 99/2 = 49, the joystick is at center.
throttle = phone.getThrottle();
steering = phone.getSteering();
// ID of the slider moved.
sliderId = phone.getSliderId();
// Slider value goes from 0 to 200.
sliderVal = phone.getSliderVal();
// Display button data whenever its pressed.
if (button != -1)
{
Serial.print("Button: ");
Serial.println(button);
if (button == 5)
{
msg = "GetLoadAvgs";
}
else if (button == 6)
{
msg = "GetDiskSpace";
}
else if (button == 7)
{
msg = "GetApache2Procs";
}
else if (button == 8)
{
msg = "GetLastBackup";
}
else if (button == 9)
{
msg = "GetSSHDStatus";
}
else
{
//phone.sendMessage("Button: " + String(button));
msg = "Button: " + String(button);
}
UDPSend udp2 = AISnb.sendUDPmsgStr(serverIP, serverPort, msg);
Serial.println("You sent to NB-IOT: " + msg);
}
// Display slider data when slider moves
if (sliderId != -1)
{
Serial.print("Slider ID: ");
Serial.print(sliderId);
Serial.print("\tValue: ");
Serial.println(sliderVal);
}
// Display throttle and steering data if steering or throttle value is changed
if (prevThrottle != throttle || prevSteering != steering)
{
Serial.print("Throttle: ");
Serial.print(throttle);
Serial.print("\tSteering: ");
Serial.println(steering);
prevThrottle = throttle;
prevSteering = steering;
}
// If a text from the phone was sent print it to the serial monitor
if (str != "")
{
Serial.println(str);
}
// Send string from serial command line to the phone. This will alert the user.
if (Serial.available())
{
Serial.write("send: ");
String str = Serial.readString();
phone.sendMessage(str); // phone.sendMessage(str) sends the text to the phone.
Serial.print(str);
Serial.write('\n');
}
}
void doNBIOT()
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval and ENABLE_NBIOT_PING)
{
cnt++;
Serial.println("Ping Count: " + String(cnt) + "\n");
// Send data in String
UDPSend udp0 = AISnb.sendUDPmsgStr(serverIP, serverPort, "Ping Count: " + String(cnt));
UDPSend udp = AISnb.sendUDPmsgStr(serverIP, serverPort, udpData + " " + String(cnt));
previousMillis = currentMillis;
}
UDPReceive resp = AISnb.waitResponse();
if (resp.data.length() > 0)
{
String reply = AISnb.toString(resp.data);
reply.replace(":", "\n");
phone.sendMessage(reply);
Serial.println("Received by NB-IOT sketch: " + resp.data);
Serial.println('\n');
}
}
I just moved away from a T3 line back to a dial up I just wanted to know would a P200 with 64meg and a 4 gig hard drive be ok for a linux server for an additional 3 pcs all running win98. I will be dialing into an isp using a 56k v90 modem.
Any support or help will be great. (3 Replies)
Hello all
this is general question , if i have web server installed in my local pc and i have client that connecting to that web server
can i force it always to go via the internet network ?
the reason im asking is .. that im noticed when i close my internet connection i still can connect to my... (2 Replies)
hi i have linux server connected to internet through a switch/router. i have opened a port on the router and i am able to connect to the server if iptables is off. but when it is on i cant.
i want to create a rule in iptables so that it accepts packets coming from a particular datacard. it... (7 Replies)
In my further exploration of Arduino, today I decided to install the arduino-cli on my mac today.
https://github.com/arduino/arduino-cli
I followed the instructions for macOS but when I got to this part:
arduino-cli board list
I got the dreaded "Unknown" Fully Qualified Board Name... (1 Reply)
My favorite projects are always related to the "latest" tech in command and control, networking and network communications. This Elecrow GSM/GPRS/EDGE SIM5360E 3G Shield seems to be the "latest and the greatest" as far as 3G and GPS, as far as I can see so far, but I has it drawbacks for sure.... (6 Replies)
Today I received my NB-IoT Arduino Shield for AIS (Thailand). Here is a "pinout" photo of the shield.
My shield looks just like the one above, for the most part. I'll post another photo of the actual device later.
When I received the shield in the mail, I went immediately to a local... (8 Replies)
Normally I have very good experiences buying from AliExpress, but in this case with Elecrow, I'm disappointed.
After confirming with Elecrow on AliExpress that their Elecrow GSM/GPRS/EDGE SIM5360E 3G Shield for Arduino would work with 3G SIM cards in Thailand, I purchased one. My plan was to... (1 Reply)
Here is a sketch to do basic testing for the Arduino UNO and the MLT-BT04.
This BLE module works with IOS (iPhone) and I'll add some details on my IOS testing with an iPhone in a follow-up post.
For now, here is the basic BLE (HM-10) sketch for the Arduino UNO:
/*
Arduino test-code... (7 Replies)
With a little bit of work, was able to build a nice "Wuhan Coronavirus Status" app using MQTT and the IoT-OnOff app. More on this technique here:
ESP32 (ESP-WROOM-32) as an MQTT Client Subscribed to Linux Server Load Average Messages
The result turned out nice, I think. I like the look and... (10 Replies)
Normally I'm not into kits, but I thought my wife would enjoy this one since she is a big fan of robots and droids on StarWars!
We are done with the basic mechanical assembly and starting on the electronics assembly today.
The robot's "brain" consists of three levels. The Arduino board, on... (5 Replies)