Skip to content

Commit 7fd8ad6

Browse files
Added sketch and removed dupe folder
1 parent ca3bff1 commit 7fd8ad6

File tree

6 files changed

+85
-4974
lines changed

6 files changed

+85
-4974
lines changed

content/hardware/04.pro/carriers/portenta-max-carrier/tutorials/Cat M1 and MB IoT/assets/Connect-H7-to-Max-carrier.svg

Lines changed: 0 additions & 2871 deletions
This file was deleted.

content/hardware/04.pro/carriers/portenta-max-carrier/tutorials/Cat M1 and MB IoT/assets/Sim-card-and-antenna-on-Max-carrier.svg

Lines changed: 0 additions & 1998 deletions
This file was deleted.

content/hardware/04.pro/carriers/portenta-max-carrier/tutorials/Cat M1 and MB IoT/content.md

Lines changed: 0 additions & 104 deletions
This file was deleted.

content/hardware/04.pro/carriers/portenta-max-carrier/tutorials/catM1-and-NBIoT/content.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ If you prefer to use one communication technology over the other, then this can
7171

7272
### Programming the Board
7373

74-
Now open the **NBWebClient** example, this is located inside the **MKRNB**. This sketch will connect the our setup to a website and print its content in the serial monitor.
74+
Now open the **NBWebClient** example, this is located inside the **MKRNB**. The full sketch will also be included later in this tutorial. This sketch will connect the our setup to a website and print its content in the serial monitor.
7575

7676
This sketch uses a secret.h file to store sensitive information, like the PIN code for the SIM card. First we need to go to the **arduino_secrets.h** tab and enter our PIN code into the **Secret_pinnumber** variable.
7777

@@ -85,6 +85,90 @@ When the sketch is uploaded, open the serial monitor to see the result. You will
8585

8686
![Result in the serial monitor](assets/result-serial-monitor.png)
8787

88+
### Full sketch
89+
90+
```arduino
91+
92+
// libraries
93+
#include <MKRNB.h>
94+
95+
#include "arduino_secrets.h"
96+
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
97+
// PIN Number
98+
const char PINNUMBER[] = SECRET_PINNUMBER;
99+
100+
// initialize the library instance
101+
NBClient client;
102+
GPRS gprs;
103+
NB nbAccess;
104+
105+
// URL, path and port (for example: example.org)
106+
char server[] = "example.org";
107+
char path[] = "/";
108+
int port = 80; // port 80 is the default for HTTP
109+
110+
void setup() {
111+
// initialize serial communications and wait for port to open:
112+
Serial.begin(9600);
113+
while (!Serial) {
114+
; // wait for serial port to connect. Needed for native USB port only
115+
}
116+
117+
Serial.println("Starting Arduino web client.");
118+
// connection state
119+
boolean connected = false;
120+
121+
// After starting the modem with NB.begin()
122+
// attach to the GPRS network with the APN, login and password
123+
while (!connected) {
124+
if ((nbAccess.begin(PINNUMBER) == NB_READY) &&
125+
(gprs.attachGPRS() == GPRS_READY)) {
126+
connected = true;
127+
} else {
128+
Serial.println("Not connected");
129+
delay(1000);
130+
}
131+
}
132+
133+
Serial.println("connecting...");
134+
135+
// if you get a connection, report back via serial:
136+
if (client.connect(server, port)) {
137+
Serial.println("connected");
138+
// Make a HTTP request:
139+
client.print("GET ");
140+
client.print(path);
141+
client.println(" HTTP/1.1");
142+
client.print("Host: ");
143+
client.println(server);
144+
client.println("Connection: close");
145+
client.println();
146+
} else {
147+
// if you didn't get a connection to the server:
148+
Serial.println("connection failed");
149+
}
150+
}
151+
152+
void loop() {
153+
// if there are incoming bytes available
154+
// from the server, read them and print them:
155+
if (client.available()) {
156+
Serial.print((char)client.read());
157+
}
158+
159+
// if the server's disconnected, stop the client:
160+
if (!client.available() && !client.connected()) {
161+
Serial.println();
162+
Serial.println("disconnecting.");
163+
client.stop();
164+
165+
// do nothing forevermore:
166+
for (;;)
167+
;
168+
}
169+
}
170+
```
171+
88172
### Troubleshoot
89173

90174
If the code is not working, there are some common issues we can troubleshoot:

0 commit comments

Comments
 (0)