Skip to content

Commit 8ac66f1

Browse files
author
Catalin Ioana
authored
Merge pull request #180 from pycom/pygate_doc
Update Pygate documentation
2 parents 5acb3b6 + aee955b commit 8ac66f1

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

content/tutorials/all/PyGate.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,127 @@ To stop the Pygate at any time use:
259259
- using deinit function `machine.pygate_deinit()`
260260

261261
that will stop GW tasks and safely power off the Concentrator.
262+
263+
264+
__Note__: The Pygate packet forwarder is a legacy packet forwarder, you must make sure you use check legacy packet forwarder option in TTN as shown below.
265+
266+
![alt_text](https://wiki.dragino.com/images/c/c6/TTN_Create_Gateway_0.png)
267+
268+
269+
## Pygate APIs
270+
271+
###machine Module
272+
273+
#### machine.pygate\_init([buff])
274+
275+
This function is used to initialize Pygate
276+
277+
- `buff`: data contents of gateway global config json file
278+
279+
when no parameter is passed to function the Pygate is just powered on. (will be useful when using pygate as just a concentrator controllable via uart by another device eg. RPi)
280+
281+
#### machine.pygate\_deinit()
282+
283+
Shuts down concentrator.
284+
285+
#### machine.pygate\_cmd\_decode(buff)
286+
287+
send lora gateway command to concentrator, this is useful when packet forwarder / HAL software is run on a different device (eg. Rpi) and commands to concentrator are passed to Pygate via uart
288+
289+
#### machine.pygate\_cmd\_get()
290+
291+
Get command execution result from concentrator.
292+
293+
Example script when running Packet forwarder sw on a different device:
294+
295+
```python
296+
from machine import UART
297+
import machine
298+
import time
299+
import os
300+
import gc
301+
302+
machine.pygate_init(None)
303+
time.sleep(3)
304+
305+
uart = UART(1, 115200, timeout_chars=40, pins=('P23', 'P22'))
306+
307+
while True:
308+
if uart.any():
309+
rx_data = uart.read()
310+
machine.pygate_cmd_decode(rx_data)
311+
tx_data = machine.pygate_cmd_get()
312+
l = uart.write(tx_data)
313+
else:
314+
time.sleep_us(10)
315+
```
316+
317+
#### machine.callback(trigger, handler=None, arg=None)
318+
319+
- `trigger`: A trigger event(s) for invoking the callback function `handler`, the triggers/events are:
320+
321+
`machine.PYGATE_START_EVT`
322+
323+
`machine.PYGATE_STOP_EVT`
324+
325+
`machine.MP_QSTR_PYGATE_ERROR_EVT`
326+
327+
- `handler`: The callback function to be called, when not passed to function the any pre-registered callback will be disabled/removed
328+
329+
- `arg`: Optional arg to be bassed to callback function.
330+
331+
#### machine.events()
332+
333+
Get the pygate events
334+
335+
336+
337+
## Pygate Ethernet adapter APIs
338+
339+
`network.ETH` module
340+
341+
### ETH.init(hosname=None)
342+
343+
This function starts Ethernet interface and enables the ethernet adapter.
344+
345+
`hostname`: set the interface hostname.
346+
347+
### ETH. ifconfig(config=\['dhcp' or configtuple\])
348+
349+
With no parameters given returns a 4-tuple of (ip, subnet_mask, gateway, DNS_server).
350+
351+
If dhcp is passed as a parameter then the DHCP client is enabled and the IP params are negotiated with the dhcp server.
352+
353+
If the 4-tuple config is given then a static IP is configured. For instance:
354+
355+
`eth.ifconfig(config=('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))`
356+
357+
### ETH.hostname(string)
358+
359+
Set interface host name.
360+
361+
### ETH.mac()
362+
363+
Get the ethernet interface mac address.
364+
365+
### ETH.deinit()
366+
367+
shuts down ethernet interface.
368+
369+
### ETH.isconnected(Bool)
370+
371+
Returns `True` if the ethernet if link is up and IP is accquired, `Fasle` otherwise
372+
373+
### ETH.register(reg, cmd, value)
374+
375+
Write/Read specific register from/to the ksz8851 ethernet controller
376+
377+
`cmd`: 0 to read , 1 to write
378+
379+
Ex: to read register 0x90
380+
381+
`eth.register(0x90,0)`
382+
383+
to write:
384+
385+
`eth.register(0x90, 1, 0x0000)`

0 commit comments

Comments
 (0)