example code where mkr 1500 sends data to hologram dash

does anyone have code that may help me with this? im designing a truck alarm system that was originally supposed to text me when it’s tripped but i’m having trouble receiving texts with my phone from hologram and i figured an email alert would work just as well. and also cost less in data. i just can’t find anything that sends data. the NBSSLWebClient example only reads from it’s connected server.

i’m a beginner and i’m not sure if i’m going about this the correct way either. is this the best way to do what seems like a simple task? alerting myself through my phone that my alarm has tripped.

i’m also unsure if i should connect the modem in the void setup() or if i should connect it once the alarm has tripped. i’m thinking it may lose connection and eat up battery if i connect it at the start but the downside to starting it after the alarm would be a delay in the alert time.

any help is much appreciated. i’m attaching the NBSSLWebClient code example that i’m referring to. i do know i’d need to change the server and port in the code to holograms.

/*
SSL Web client

This sketch connects to a website using SSL through a MKR NB 1500 board. Specifically,
this example downloads the URL "https://www.arduino.cc/asciilogo.txt" and
prints it to the Serial monitor.

Circuit:
* MKR NB 1500 board
* Antenna
* SIM card with a data plan

created 8 Mar 2012
by Tom Igoe
*/

// libraries
#include <MKRNB.h>

#include "arduino_secrets.h" 
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[]     = SECRET_PINNUMBER;

// initialize the library instance
NBSSLClient client;
GPRS gprs;
NB nbAccess;

// URL, path and port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 443; // port 443 is the default for HTTPS

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
// connection state
 boolean connected = false;

 // After starting the modem with NB.begin()
 // attach to the GPRS network with the APN, login and password
 while (!connected) {
   if ((nbAccess.begin(PINNUMBER) == NB_READY) &&
    (gprs.attachGPRS() == GPRS_READY)) {
  connected = true;
} else {
  Serial.println("Not connected");
  delay(1000);
}
}

 Serial.println("connecting...");

// if you get a connection, report back via serial:
if (client.connect(server, port)) {
  Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
 } else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for (;;)
      ;
  }
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.