Skip to content

Commit 59c74aa

Browse files
authored
Fix broken examples (#66)
* Put config variables in example sketch. * Update license files * Fix counter example * Fix positioning example * Fix mqtt example
1 parent 3283066 commit 59c74aa

10 files changed

Lines changed: 328 additions & 325 deletions

File tree

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ out/
2727

2828
.idea/$CACHE_FILE$
2929

30-
# Ignore config.py files from examples
31-
examples/**/config.py
32-
3330
# Ignore log files from modem_passthrough utility
3431
util/modem_passthrough/*.log

examples/counter/LICENSE

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
DPTECHNICS 5 CLAUSE LICENSE
2-
3-
Copyright (C) 2023, DPTechnics bv
1+
Copyright (C) 2026, DPTechnics bv
42
All rights reserved.
53

6-
Redistribution and use in source and binary forms, with or without modification,
7-
are permitted provided that the following conditions are met:
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
86

9-
1. Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
119

12-
2. Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
1513

16-
3. Neither the name of DPTechnics bv nor the names of its contributors may be
17-
used to endorse or promote products derived from this software without
18-
specific prior written permission.
14+
3. Neither the name of DPTechnics bv nor the names of its contributors may
15+
be used to endorse or promote products derived from this software
16+
without specific prior written permission.
1917

20-
4. This software, with or without modification, must only be used with a
21-
Walter board from DPTechnics bv.
18+
4. This software, with or without modification, must only be used with a
19+
Walter board from DPTechnics bv.
2220

23-
5. Any software provided in binary form under this license must not be reverse
24-
engineered, decompiled, modified and/or disassembled.
21+
5. Any software provided in binary form under this license must not be
22+
reverse engineered, decompiled, modified and/or disassembled.
2523

2624
THIS SOFTWARE IS PROVIDED BY DPTECHNICS BV “AS IS” AND ANY EXPRESS OR IMPLIED
2725
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2826
MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
2927
DISCLAIMED. IN NO EVENT SHALL DPTECHNICS BV OR CONTRIBUTORS BE LIABLE FOR ANY
3028
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3129
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3432
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3533
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

examples/counter/config.example.py

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

examples/counter/main.py

Lines changed: 63 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,56 @@
2424
WalterModemRsp
2525
)
2626

27-
import config # type: ignore
27+
#region CONFIG VARIABLES
28+
29+
# IMPORTANT
30+
# This is an example sketch with verbose comments and logging,
31+
# in production codde such verbose comments could be left out to reduce codesize.
32+
33+
CELL_APN = ''
34+
"""
35+
The cellular Access Point Name (APN).
36+
Set to the APN provided by your network provider.
37+
Leave blank for automatic APN detection only if your provider supports it
38+
"""
39+
40+
APN_USERNAME = ''
41+
"""
42+
The username for APN authentication.
43+
Typically, this is not required and should be left blank.
44+
Only provide a username if your network provider explicitly mandates it.
45+
"""
46+
47+
APN_PASSWORD = ''
48+
"""
49+
The password for APN authentication.
50+
This is generally unnecessary and should remain blank.
51+
Set a password only if it is specifically required by your network provider.
52+
"""
53+
54+
AUTHENTICATION_PROTOCOL = WalterModemPDPAuthProtocol.NONE
55+
"""
56+
The authentication protocol to use if requiren.
57+
Leave as none when no username/password is set.
58+
"""
59+
60+
SIM_PIN = None
61+
"""
62+
Optional: Set this only if your SIM card requires a PIN for activation.
63+
Most IoT SIMs do not need this.
64+
"""
65+
66+
SERVER_ADDRESS = 'walterdemo.quickspot.io'
67+
"""
68+
The address of the Walter Demo server.
69+
"""
70+
71+
SERVER_PORT = 1999
72+
"""
73+
The UDP port of the Walter Demo server.
74+
"""
75+
76+
#endregion
2877

2978
modem = Modem(SocketMixin, load_default_power_saving_mixin=False)
3079
"""
@@ -149,7 +198,7 @@ async def unlock_sim() -> bool:
149198

150199
# Give the modem time to detect the SIM
151200
await asyncio.sleep(2)
152-
if await modem.unlock_sim(pin=config.SIM_PIN):
201+
if await modem.unlock_sim(pin=SIM_PIN):
153202
print(' - SIM unlocked')
154203
else:
155204
print(' - Failed to unlock SIM card')
@@ -173,20 +222,20 @@ async def setup():
173222
print('Modem communication error')
174223
return False
175224

176-
if config.SIM_PIN != None and not await unlock_sim():
225+
if SIM_PIN != None and not await unlock_sim():
177226
return False
178227

179228
if not await modem.pdp_context_create(
180-
apn=config.CELL_APN,
229+
apn=CELL_APN,
181230
rsp=modem_rsp
182231
):
183232
print('Failed to create socket')
184233
return False
185234

186-
if config.APN_USERNAME and not await modem.pdp_set_auth_params(
187-
protocol=config.AUTHENTICATION_PROTOCOL,
188-
user_id=config.APN_USERNAME,
189-
password=config.APN_PASSWORD
235+
if APN_USERNAME and not await modem.pdp_set_auth_params(
236+
protocol=AUTHENTICATION_PROTOCOL,
237+
user_id=APN_USERNAME,
238+
password=APN_PASSWORD
190239
):
191240
print('Failed to set PDP context authentication parameters')
192241

@@ -195,18 +244,15 @@ async def setup():
195244
return False
196245

197246
print('Creating socket')
198-
if await modem.socket_create(rsp=modem_rsp):
199-
socket_id = modem_rsp.socket_id
200-
else:
247+
if not await modem.socket_config(ctx_id=1, pdp_ctx_id=1, rsp=modem_rsp):
201248
print('Failed to create socket')
202249
return False
203250

204251
print('Connecting socket')
205-
if not await modem.socket_connect(
206-
remote_host=config.SERVER_ADDRESS,
207-
remote_port=config.SERVER_PORT,
208-
local_port=config.SERVER_PORT,
209-
socket_id=socket_id
252+
if not await modem.socket_dial(
253+
ctx_id=1,
254+
remote_addr=SERVER_ADDRESS,
255+
remote_port=SERVER_PORT,
210256
):
211257
print('Failed to connect socket')
212258
return False
@@ -221,7 +267,7 @@ async def loop():
221267
data_buffer.append(counter & 0xff)
222268

223269
print('Attempting to transmit data')
224-
if not await modem.socket_send(data=data_buffer, socket_id=socket_id):
270+
if not await modem.socket_send(ctx_id=1, data=data_buffer):
225271
print('Failed to transmit data')
226272
return False
227273

examples/mqtt/LICENSE

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
DPTECHNICS 5 CLAUSE LICENSE
2-
3-
Copyright (C) 2023, DPTechnics bv
1+
Copyright (C) 2026, DPTechnics bv
42
All rights reserved.
53

6-
Redistribution and use in source and binary forms, with or without modification,
7-
are permitted provided that the following conditions are met:
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
86

9-
1. Redistributions of source code must retain the above copyright notice, this
10-
list of conditions and the following disclaimer.
7+
1. Redistributions of source code must retain the above copyright notice,
8+
this list of conditions and the following disclaimer.
119

12-
2. Redistributions in binary form must reproduce the above copyright notice,
13-
this list of conditions and the following disclaimer in the documentation
14-
and/or other materials provided with the distribution.
10+
2. Redistributions in binary form must reproduce the above copyright
11+
notice, this list of conditions and the following disclaimer in the
12+
documentation and/or other materials provided with the distribution.
1513

16-
3. Neither the name of DPTechnics bv nor the names of its contributors may be
17-
used to endorse or promote products derived from this software without
18-
specific prior written permission.
14+
3. Neither the name of DPTechnics bv nor the names of its contributors may
15+
be used to endorse or promote products derived from this software
16+
without specific prior written permission.
1917

20-
4. This software, with or without modification, must only be used with a
21-
Walter board from DPTechnics bv.
18+
4. This software, with or without modification, must only be used with a
19+
Walter board from DPTechnics bv.
2220

23-
5. Any software provided in binary form under this license must not be reverse
24-
engineered, decompiled, modified and/or disassembled.
21+
5. Any software provided in binary form under this license must not be
22+
reverse engineered, decompiled, modified and/or disassembled.
2523

2624
THIS SOFTWARE IS PROVIDED BY DPTECHNICS BV “AS IS” AND ANY EXPRESS OR IMPLIED
2725
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2826
MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
2927
DISCLAIMED. IN NO EVENT SHALL DPTECHNICS BV OR CONTRIBUTORS BE LIABLE FOR ANY
3028
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3129
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3432
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3533
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

examples/mqtt/config.example.py

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

0 commit comments

Comments
 (0)