/* Test of Web client (Eksempel-kode-1.ino) This sketch connects to a website through a MKR NB 1500 board. Specifically, this example downloads the URL "http://example.org/" 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 Igo Modified 30. aug. 2022 by HÃ¥vard Holm/Nils Kr. Rossing */ // libraries #include // #include "arduino_secrets.h" // Please enter your sensitive data in the Secret tab or arduino_secrets.h // PIN Number const char PINNUMBER[] = ""; // initialize the library instance NBClient client; GPRS gprs; NB nbAccess; // URL, path and port (for example: example.org) char server[] = "sensor.marin.ntnu.no"; char path[] = "/cgi-bin/tof.cgi?"; int port = 80; // port 80 is the default for HTTP void setup() { char buffer[256]; // 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) && if ((nbAccess.begin("", true, true) == 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("/cgi-bin/test.cgi?Gr1,lat=67.8,lon=7.8"); //sprintf(buffer, "/cgi-bin/tof.cgi?haavard,lat=%lf,lon=%lf", 67.5, 5.6); sprintf(buffer, "/cgi-bin/tof.cgi?Gr-no,lat=%lf,lon=%lf", 67.512345, 5.654321); client.print(buffer); 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()) { Serial.print((char)client.read()); } // if the server's disconnected, stop the client: if (!client.available() && !client.connected()) { Serial.println(); Serial.println("disconnecting."); client.stop(); // do nothing forevermore: for (;;) ; } }