Sending temprature and gps data using a NB-IoT

I’m new to the Narrowband transmittors and how to effectively setup code and actually being able to transmit data using it and I was wondering if someone could help me modify an example code to fit my requirements.
I am using a AdaFruit Ultimate breakout V3 gps and a Maxim DS18B20 temprature sensor. I have made code to work with the temprature sensor and gps at the same time but sending it using the Narrowband transmitter is something quite different

The code for GPS and Temp sensor

// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_GPS.h>

// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
#define GPSSerial Serial1
Adafruit_GPS GPS(&GPSSerial);
#define GPSECHO false
uint32_t timer = millis();
/*
 * The setup function. We only start the sensors here
 */

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo And AdaFruit GPS");

  // Start up the library
  sensors.begin();
  GPS.begin(9600);
  GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  //GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate  
  GPS.sendCommand(PGCMD_ANTENNA);
  delay(1000); 
  GPSSerial.println(PMTK_Q_RELEASE);
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{ 
  // read data from the GPS in the 'main loop'
  char c = GPS.read();
  // if you want to debug, this is a good time to do it!
  if (GPSECHO)
    if (c) Serial.print(c);
  // if a sentence is received, we can check the checksum, parse it...
  if (GPS.newNMEAreceived()) {
    // a tricky thing here is if we print the NMEA sentence, or data
    // we end up not listening and catching other sentences!
    // so be very wary if using OUTPUT_ALLDATA and trytng to print out data
    Serial.println(GPS.lastNMEA()); // this also sets the newNMEAreceived() flag to false
    if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
      return; // we can fail to parse a sentence in which case we should just wait for another
  }
  // if millis() or timer wraps around, we'll just reset it
  if (timer > millis()) timer = millis();
     
  // approximately every 2 seconds or so, print out the current stats
  if (millis() - timer > 2000) {
    timer = millis(); // reset the timer
    Serial.print("\nTime: ");
    Serial.print(GPS.hour, DEC); Serial.print(':');
    Serial.print(GPS.minute, DEC); Serial.print(':');
    Serial.print(GPS.seconds, DEC); Serial.print('.');
    Serial.println(GPS.milliseconds);
    Serial.print("Date: ");
    Serial.print(GPS.day, DEC); Serial.print('/');
    Serial.print(GPS.month, DEC); Serial.print("/20");
    Serial.println(GPS.year, DEC);
    Serial.print("Fix: "); Serial.print((int)GPS.fix);
    Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
    if (GPS.fix) {
      Serial.print("Location: ");
      Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
      Serial.print(", ");
      Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
      Serial.print("Speed (kmh): "); Serial.println(GPS.speed);
      Serial.print("Angle: "); Serial.println(GPS.angle);
      Serial.print("Altitude:(m) "); Serial.println(GPS.altitude);
      Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
      // call sensors.requestTemperatures() to issue a global temperature 
      // request to all devices on the bus
      sensors.requestTemperatures(); // Send the command to get temperatures
      // After we got the temperatures, we can print them here.
      // We use the function ByIndex, and as an example get the temperature from the first sensor only.
      Serial.print("Temperature is: ");
      Serial.println(sensors.getTempCByIndex(0)); 
    }
  }
}

The Example code for the transmitter

/***********************************************************************

#include "TelenorNBIoT.h"

#ifdef SERIAL_PORT_HARDWARE_OPEN

#define ublox SERIAL_PORT_HARDWARE_OPEN
#else
/*
 * For Arduino boards with only one hardware serial port (like Arduino UNO). It
 * is mapped to USB, so we use SoftwareSerial on pin 10 and 11 instead.
 */
#include <SoftwareSerial.h>
SoftwareSerial ublox(10, 11);
#endif

// Configure mobile country code, mobile network code and access point name
// See https://www.mcc-mnc.com/ for country and network codes
// Access Point Namme: mda.ee (Telenor NB-IoT Developer Platform)
// Mobile Country Code: 242 (Norway)
// Mobile Network Operator: 01 (Telenor)
TelenorNBIoT nbiot("mda.ee", 242, 01);

IPAddress remoteIP(172, 16, 15, 14);
int REMOTE_PORT = 1234;

void setup() {
  Serial.begin(9600);
  while (!Serial) ;
  printHelp();

  ublox.begin(9600);
  nbiot.begin(ublox);
}

void printHelp() {
  Serial.println(F("====================================="));
  Serial.println(F("h. . . . . Display help"));
  Serial.println(F("g. . . . . Check GPRS status (aka connected)"));
  Serial.println(F("n. . . . . Create socket"));
  Serial.println(F("c. . . . . Close socket"));
  Serial.println(F("s. . . . . Send packet \"Hello\""));
  Serial.println(F("r. . . . . ReciveFrom"));
  Serial.println(F("i. . . . . IMEI"));
  Serial.println(F("I. . . . . IMSI"));
  Serial.println(F("f. . . . . Firmware version"));
  Serial.println(F("x. . . . . error command"));
  Serial.println(F("b. . . . . reboot"));
  Serial.println(F("o. . . . . Go online"));
  Serial.println(F("O. . . . . Go offline"));
  Serial.println(F("====================================="));
}

unsigned long long tmp;
char buf[16];
char databuf[32];
uint16_t tmplen = 32;

void loop() {
  if (Serial.available()) {
    switch (Serial.read()) {
      case 'h':
        printHelp();
        break;

      case 'g':
        if (nbiot.isConnected()) {
          Serial.println(F("Module is online"));
        } else {
          Serial.println(F("Module is not connected"));
        }
        break;

      case 'i':
        Serial.print(F("IMEI = "));
        Serial.println(nbiot.imei());
        break;

      case 'I':
        Serial.print(F("IMSI = "));
        Serial.println(nbiot.imsi());
        break;

      case 'f':
        Serial.print(F("Firmware version = "));
        Serial.println(nbiot.firmwareVersion());
        break;

      case 'n':
        if (nbiot.createSocket()) {
          Serial.println(F("Created socket"));
        } else {
          Serial.println(F("Unable to create socket"));
        }
        break;

      case 'c':
        if (nbiot.closeSocket()) {
          Serial.println(F("Closed socket"));
        } else {
          Serial.println(F("Unable to close socket"));
        }
        break;

      case 's':
        if (nbiot.sendString(remoteIP, REMOTE_PORT, "Hello")) {
          Serial.println(F("Data sent"));
        } else {
          Serial.println(F("Unable to send data"));
        }
        break;

      case 'r':
        if (nbiot.receiveFrom(NULL, NULL, databuf, &tmplen)) {
          Serial.println(F("Received data"));
        } else {
          Serial.println(F("No data received"));
        }

      case 'b':
        if (nbiot.reboot()) {
          Serial.println(F("Rebooted successfully"));
        } else {
          Serial.println(F("Error rebooting"));
        }
        break;

      case 'O':
        if (nbiot.offline()) {
          Serial.println(F("Radio turned off"));
        } else {
          Serial.println(F("Unable to turn off radio"));
        }
        break;

      case 'o':
        if (nbiot.online()) {
          Serial.println(F("Radio turned on"));
        } else {
          Serial.println(F("Unable to turn radio on"));
        }
        break;

      default:
        break;
    }
  }
}

interactive.ino (4.87 KB)

Simple_with_gps.ino (3.59 KB)

Can you, starting from the multi-function transmitter code, create a no-option sketch that simply sends "It's Wednesday"?

If so, sending ANY string will be a piece of cake. The only challenge, and it is a very tiny challenge, will be formatting the string to send containing the data you want to send. dtostrf() and snprintf() will tackle that part.

You may have done it already, but I would not even attempt to integrate a GPS and temperature sensor into a program until I had the radio link working in 'Hello World' terms.

Then I would check the GPS part is working, printing the location to serial console, then do the same for the temperature sensor.

With all the hardware working you can now attempt to integrate it all.

srnet:
You may have done it already, but I would not even attempt to integrate a GPS and temperature sensor into a program until I had the radio link working in 'Hello World' terms.

Then I would check the GPS part is working, printing the location to serial console, then do the same for the temperature sensor.

With all the hardware working you can now attempt to integrate it all.

Yeah I done that but the intergration of the code is the most difficult part because I'm not really familiar with coding

Franktastic:
Yeah I done that but the intergration of the code is the most difficult part because I'm not really familiar with coding

How far did you get, what part is not working ?

srnet:
How far did you get, what part is not working ?

I have code so I can use the gps and temp sensor together but the gps uses the serial ports and I need those for my NB so i have to set it so gps uses digital pin 6-7 but i have problems adapting the code to do that
EDIT: I noticed now I don't even need the GPS module because the NB has its own so its just sending the Temprature over the NB