tarpn_logo
 home    builders    Search

builders ➜ Access with Python

Access with Python

KN4ORB, Aaron, made us a demo program for Python which reads some data from the node. You can run this program as shown below. Use this as a starting point for your own python node interactive project.


Here's where this program lives on github: TARPNclient.
## BASIC NODE INTERACTION PROGRAM BY KN4ORB
## This program, running on the node's Raspberry PI, logs in using the specified callsign and password
## (on a TARPN node the username is the local operator's callsign and the password is always 'p').
## Then the program will request INFO using the "I" command. 
## Note that the node will print out the USER command response as soon as we log in so you'll see that 
## in the output before the INFO command. 

import getpass
import sys
import telnetlib
import time
from time import gmtime, strftime


                           ### On a Raspberry PI, calling for itself, use 127.0.1.1.
                           ### Port 8010 goes to the G8BPQ node command line.
HOST = "127.0.1.1"
PORT = "8010"
print("program starting - we're going to log into "+HOST+" on port "+PORT);
username = "ka2dew"
password = "p"
print("using your callsign "+username+" and the trivial password 'p'");

                           ### Open a telnet session to the specified IP address and port.
tn = telnetlib.Telnet(HOST,PORT)

                           ### Echo what the node sends us, up until the :
print tn.read_until(":")

                           ## Once the node has printed the prompt for our callsign, send the callsign. 
                           ## In a more rigorous program, we could just read the prompt and send it 
                           ## back to the node. 
                           ## The G8BPQ program (pilinbpq) allows for log-in prompts and log-in names 
                           ## of whatever you want, but the TARPN installation makes it do just the 
                           ## callsign, since this is never going to be used over a public Internet! 
tn.write(username + "\r\n")

                           ## Now read in the password prompt, and write our password which is 'p' out  
                           ## to the Telnet server. 
print tn.read_until(":")
tn.write(password + "\r\n")

                           ## having written the log in informtation to the Telnet session, 
                           ## we'll sleep for a few seconds and then read and print what the Telnet 
                           ## server sent us.
print("***** Waiting 3 Seconds for the node *****\n")
time.sleep(3)
print tn.read_very_eager()

                           ## Now write "I" to the Telnet server and get the INFO text response.
tn.write("I\r\n")
print("Wrote 'I'")
time.sleep(1)
print tn.read_very_eager()

                           ### Now log out of the telnet server.  This isn't strictly necessary 
                           ### in a program which quits, because LINUX won't just leave the 
                           ### but lets close it anyway just to be neat.
                           ### Note that this is telling the server to shut us off.  This is proper.  
                           ### The other method is to use the telnetlib command to dump us.                                                    
tn.write("Bye\r\n")
tn.write("^]")
tn.write("exit\r\n")
print("#### that's all ####");

Here is what the program looked like when I ran it.

pi@taddnode:~/testcode $ python readfromnode.py
program starting - we're going to log into 127.0.1.1 on port 8010
using your callsign ka2dew and the trivial password 'p'
ka2dew:
type p:
***** Waiting 3 Seconds for the node *****


Connected to KA2DEW-2's Telnet Server

TADD:KA2DEW-2} G8BPQ Network System 6.0.14.12 for Linux (823)
Host32(KA2DEW-2)                   <--> Circuit(REED:N7RYN-2 KA2DEW-2)
Host34(KA2DEW-2)                   <--> Host01(ZDEW05:KA2DEW-5)
Circuit(ZDEW06:KA2DEW-6 KA2DEW-6)  <--> Host02(ZDEW05:KA2DEW-5)
Circuit(ZORB09:KN4ORB-9 KN4ORB-9)  <--> Host03(ZDEW05:KA2DEW-5)
Host20(ZDEW05:KA2DEW-5)            <--> Circuit(ZLTV09:N3LTV-9 KA2DEW-5)
TNC Uplink Port 32/2(KA2DEW)            
TNC Uplink Port 32/1(KA2DEW)            
Host18(ZDEW05:KA2DEW-5)            <--> Circuit(ZRGN09:K4RGN-9 KA2DEW-5)
TNC Uplink Port 32/3(KA2DEW)            
Host19(ZDEW05:KA2DEW-5)            <--> Circuit(Z4FG09:NC4FG-9 KA2DEW-5)
Host33(KA2DEW-2)                        
TNC Uplink Port 32/8(KA2DEW)            
TNC Uplink Port 32/6(KA2DEW)            
TNC Uplink Port 32/7(KA2DEW)            
TNC Uplink Port 32/4(KA2DEW)            
TNC Uplink Port 32/5(KA2DEW)            
Circuit(Z4EP09:KM4EP-9 KM4EP-9)    <--> Host04(ZDEW05:KA2DEW-5)
Circuit(TILL:K4RGN-2 K4RGN)        <--> Circuit(FIN:NC4FG-2 K4RGN)
Circuit(JAY:KM4EP-2 KM4EP-2)            
TNC Uplink Port 32/9(KA2DEW)            

Wrote 'I'
TADD:KA2DEW-2} TARPN config:  08-17-2020  #3     /tarpn.net/apr2020 

6 port node in North Raleigh
port 5  222.32  link to FIN   horizontal yagis 3 miles,     1200 baud
port 6  144.31  link to FFVC  vertical omni 8.5 miles,      1200 baud
port 7  441.475 link to JAY   crappy antennas, 2 miles      2400 baud
port 8  446.475 link to TILL  vert omni to yagi, 1.5 miles, 2400 baud
port 9  147.555 link to DOUG  horz beams, 1.1 miles,        9600 baud
port 10  51.12  link to AARON horizontal moxons 7 miles,    1200 baud
eof

Commands: CHAT HOST TRR LINUX TCHAT TINFO CONNECT BYE INFO NODES PORTS ROUTES USERS MHEARD

#### that's all ####
pi@taddnode:~/testcode $ 
© Tadd Torborg, 2020 -- all rights reserved