Skip to content

Commit d6b5c45

Browse files
committed
Conifguring things for inital rollout
1 parent ae4cf9a commit d6b5c45

12 files changed

Lines changed: 629 additions & 338 deletions

File tree

File renamed without changes.

SETUP.md renamed to ARCHIVE/SETUP.md

Lines changed: 330 additions & 330 deletions
Large diffs are not rendered by default.

AuxillaryOperations.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Auxillary Operations
2+
3+
Other things that may need doing at some point
4+
5+
## Changing device Name or Account Username/Password
6+
7+
1. `sudo raspi-config`
8+
9+
## Changing root password
10+
11+
1. `sudo passwd root`
12+
13+
## Changing WIFI network name
14+
15+
1. `sudo vim /etc/hostapd/hostapd.conf`
16+
17+
1. ssid is network name
18+
19+
1. wpa_passphrase is network password
20+
21+
## Configure WIFI as Client
22+
23+
1.
24+
25+
## Uploading Files
26+
27+
1. Use any SFTP compatible device. For example, with filezilla use the host 'sftp://pi-ip'
28+
29+
1. After logging in, may need to go up several directories. Then into `/var/www/html`
30+
31+
1. Transfer the files. Webserver provides `index.html` to clients. Server is launched with `python3 /var/www/html/server.py 192.168.4.1 8765 1 &`
32+
33+
1. If necessary, alter python launch config:
34+
35+
## Update Command Line Args for Server
36+
37+
1. `sudo vim /etc/rc.local`
38+
39+
1. update python line
40+
41+
## Create a raspberry pi image
42+
43+
1. Win32DiskImager
44+
45+
1. Copy
46+
47+
1. Can load this image to sd card in same utility or via raspberry pi imager

Examples/JoystickDrive/backend.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ function initFunction() {
2929
socket.onmessage = onSocketReceive; //called each message received
3030
socket.onclose = onSocketClose; //called each close
3131

32+
if(typeof status != 'undefined'){
33+
document.getElementById("statusPrintout").innerHTML = status;
34+
}
3235
}
3336

3437
//called when the socket establishes a connection to the server

Examples/JoystickDrive/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<script src = "backend.js"></script>
33
<script src="joystick.js"></script>
44
<script src="hostPort.js"></script>
5+
<script src="statusfile.js"></script>
56
<link rel="stylesheet" href="joystickStyles.css">
67
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
78
</head>
@@ -13,4 +14,7 @@
1314
<div id="joystick"></div>
1415
</div>
1516
</div>
17+
<div id="statusPrintout">
18+
No status file provided
19+
</div>
1620
</body>

Examples/JoystickDrive/joystickStyles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,8 @@
5454
-ms-transform: translate(-50%, -50%);
5555
transform: translate(-50%, -50%);
5656

57+
}
58+
59+
#statusPrintout{
60+
width: 100%
5761
}

Examples/JoystickDrive/server.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ async def connectionHandler(websocket, path):
5050
return connectionHandler
5151

5252

53+
def writeStatus(message):
54+
try:
55+
with open('statusfile.js', 'w') as status:
56+
print(f'status="Server status: {message}";', file=status)
57+
except Exception:
58+
pass
59+
5360
#if the python module has been launched as the main one
5461
if __name__ == "__main__":
5562
#first, we allow for command line arguments formatted such:
@@ -71,13 +78,16 @@ async def connectionHandler(websocket, path):
7178
except (IndexError, ValueError):
7279
motorInterfaceType = 0
7380

81+
writeStatus("server booting")
82+
7483
#next, write the host:port combo to a file that js can read.
7584
try:
7685
with open("hostPort.js", 'w') as fileOut:
7786
fileOut.write(f"myHost = '{host}';")
7887
fileOut.write(f"myPort = '{port}';")
7988
#with open() as syntax automatically closes the file on exit
8089
except (FileNotFoundError, FileExistsError, OSError) as e:
90+
writeStatus("server crashed writing host-port file")
8191
print("Something went wrong trying to write the hostport.js file. Type:" + str(type(e)))
8292

8393
print(f"Starting Server at {host}:{port}")
@@ -91,7 +101,7 @@ async def connectionHandler(websocket, path):
91101

92102
#This outer while loop "solves" the race condition.
93103
#More on this at the end of the file.
94-
failCtr = 5
104+
failCtr = 0
95105
while(True):
96106
#start the server
97107
server = websockets.serve(buildConnectionHandler(interface), host, port)
@@ -101,6 +111,7 @@ async def connectionHandler(websocket, path):
101111
# under normal circumstances, this means we wait forever
102112
asyncio.get_event_loop().run_until_complete(server)
103113
print("server started successfully.")
114+
writeStatus("server started nominally")
104115
failCtr = -1
105116
asyncio.get_event_loop().run_forever()
106117
#any code down here would not be reachable until the server closes its socket
@@ -110,13 +121,16 @@ async def connectionHandler(websocket, path):
110121
#the interrupt was fired (ctrl-c), time to exit
111122
#note, the interrupt wont happen till the next async event happens
112123
print("Exiting via KeyboardInterrupt")
124+
writeStatus("Exited via keyboard interrupt")
113125
exit(-1)
114126
except OSError as e:
115127
failCtr+=1
116-
if(failCtr > 5):
117-
print("The server startup failed too many times, allowing exception to fire.")
128+
if(failCtr % 10 == 0):
129+
print("The server startup failed too many times")
118130
print("\tThis may be a result of too many packages slowing down the loading of the network interface.")
119-
raise e #allow the error to fire.
131+
print(f"\t{e}")
132+
# raise e #allow the error to fire.
133+
writeStatus(f"Sever bind failure after {failCtr} retries")
120134
else:
121135
sleep(5)
122136

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
status="server started nominally";

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Spencer Gautreaux
3+
Copyright (c) 2020 Aggie Robotics
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Quickstart.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Quick Start
2+
3+
1. Download the latest image from the releases tab
4+
5+
1. Put this image on an sd card via either raspbery pi imager utility or Win32DiskImager
6+
7+
1. Provide power and go for it
8+
9+
1. See [Auxillary Operations](AuxillaryOperations.md) for some common actions
10+
11+
# Default Values
12+
13+
Key Values in the default image
14+
15+
## Accounts
16+
17+
* Default username = `pi`
18+
19+
* Default password = `raspberry`
20+
21+
## Root
22+
23+
* Root password, if prompted, is `AggieRobotics`
24+
25+
## Key Files
26+
27+
* Dir: `/var/www/html/`
28+
29+
* `index.html`
30+
31+
* `server.py`
32+
33+
## Wifi
34+
35+
* SSID (Network Name) = `Sumobot`
36+
37+
* Password = `AggieRobotics`
38+
39+
## DHCP
40+
41+
* Range `192.168.4.1` to `192.168.4.20`
42+
43+
* Host is `192.168.4.1`
44+
45+
* Lease Time is `24h`
46+
47+
## IPTables
48+
49+
* All inbound connections on all interfaces redirect to local

0 commit comments

Comments
 (0)