Refactored and organized wifi and weather examples

This commit is contained in:
Nathan Hendler 2022-07-16 10:56:02 -07:00
parent f1640ca40f
commit 28ca004d03
66 changed files with 345 additions and 26 deletions

View File

@ -1,17 +0,0 @@
1. Load `00_wifi_scan-basic.dsk` into your Apple II
1. Load `00_wifi_scan-basic.ino` into your apple2idiot card in slot 2.
At BASIC prompt on Apple II do...
```BASIC
RUN CWIFISCAN.BAS
RUN WIFISCAN.BAS
RUN SHOWIP.BAS
```
CWIFISCAN tells the card to scan for access points.
WIFISCAN shows the results, and lets you choose an access point and enter a password
SHOWIP does just that.

View File

@ -0,0 +1,43 @@
# Overview
This is a very simple example of how to scan for wifi access points and then
connect to one. It is a very basic example of how the Apple2Idiot card and the
Apple II can work together. Practically, this example isn't very useful,
because after you connect you can not really do anything except recscan.
There's no code in `01_wifi_scan-basic.ino` to do anything else.
## Getting it to work
#. Load `01_wifi_scan-basic.dsk` into your Apple II
#. Load `01_wifi_scan-basic.ino` into your apple2idiot card in slot 2.
At BASIC prompt on Apple II do...
```BASIC
RUN CWIFISCAN.BAS
RUN WIFISCAN.BAS
RUN SHOWIP.BAS
```
CWIFISCAN tells the card to scan for access points.
WIFISCAN shows the results, and lets you choose an access point and enter a password
SHOWIP does just that.
## Building the .dsk image
```bash
. ./make-disk.bash
```
## Flashing card using arduino-cli
You can use the arduino ide to get the .ino file onto the Apple2Idiot card. Or you can use the `arduino-cli` which is explained here...
```bash
arduino-cli compile --fqbn esp32:esp32:nodemcu-32s .
arduino-cli upload -p /dev/ttyUSB0 --fqbn esp32:esp32:esp32-poe-iso .
```

View File

@ -17,8 +17,12 @@ Apple2Idiot a2i = Apple2Idiot();
#define COMMAND_SET_CITY 201
#define COMMAND_FETCH_WEATHER 205
const char* wifi_ssid = "GSO";
const char* wifi_password = "xerxes27";
#include "credentials.h"
//const char* wifi_ssid = "HotelMcCoy-Guest";
//const char* wifi_password = "travelforall";
char wifi_ssid[] = WIFI_SSID; // your network SSID (name)
char wifi_password[] = WIFI_PASSWORD; // your network password
/*******************/
/* Weather Service */
@ -44,6 +48,10 @@ byte lastAppleCommand = 0;
################################################*/
void setup() {
Serial.println("Starting 15_fixed_essid_weather-cc65.ino after a quick delay so that we have time to connect a serial monitor after restart and see what's going on");
delay(3000);
Serial.println("Starting 15_fixed_essid_weather-cc65.ino");
Serial.begin(115200);
a2i.init();
@ -76,7 +84,7 @@ byte fetch_weather() {
byte result = 0;
HTTPClient http;
//const String request_url = weather_url + "q=Tucson,us&APPID=" + weather_service_api_key;
const String request_url = weather_url + "q=" + city_name + "," + country_code + "&APPID=" + weather_service_api_key;
const String request_url = weather_url + "q=" + city_name + "," + country_code + "&APPID=" + WEATHER_ACCESS_TOKEN;
Serial.println(request_url);
http.begin(request_url);
int httpCode = http.GET(); //Make the request

View File

@ -0,0 +1,6 @@
# Arduno sketch for Apple2 Internet Weather Client Examples
For now, this works with both the basic and and cc65 clients
`../15_fixed_essid_weather-basic`
`../15_fixed_essid_weather-cc65`

View File

@ -0,0 +1,12 @@
#ifndef CREDENTIALS_H
#define CREDENTIALS_H
#include "credentials.h"
// copy credentials.h.sample to credentials.h and edit
// so it contains your passwords and tokens.
#define WIFI_SSID "XXXXXXXXXXXXXXX";
#define WIFI_PASSWORD "XXXXXXXXXXXXXXX";
#define WEATHER_ACCESS_TOKEN "XXXXXXXXXXXXXXX"
#endif

View File

@ -0,0 +1,4 @@
# Very simple Apple II Internet weather client example
* Use the arduino-cli or ide to transfer `../15_fixed_essid_weather-arduino/15_fixed_essid_weather-arduino.ino` to the ESP32 on the apple2idiot card.
* Use `WEATHER.BAS` on your Apple ][.

View File

@ -0,0 +1,86 @@
10 CA = 49664
20 AA = CA +1
30 CC$ = ""
35 CITY$ = ""
100 PRINT
110 PRINT "----"
120 PRINT "MENU"
130 PRINT "(1) COUNTRY","",CC$
140 PRINT "(2) CITY","",CITY$
150 PRINT "(3) FETCH WEATHER"
160 PRINT "(4) SHOW WEATHER"
170 PRINT "(0) QUIT"
175 PRINT
180 INPUT "SELECT: ";S
190 IF S >4 THEN GOTO 100
200 IF S = 0 THEN END
210 IF S = 1 THEN GOTO 1000
220 IF S = 2 THEN GOTO 2000
230 IF S = 3 THEN GOTO 3000
240 IF S = 4 THEN GOTO 4000
250 GOTO 100
1000 INPUT "COUNTRY CODE: ";CC$
1010 WS$ = CC$
1020 WA = AA +1
1030 GOSUB 10000
1040 POKE AA,200 : REM SET COUNTRY
1050 GOTO 100
2000 INPUT "CITY: ";CITY$
2010 WS$ = CITY$
2020 WA = AA +1
2030 GOSUB 10000
2040 POKE AA,201 : REM SET CITY
2050 GOTO 100
3000 POKE AA,205 : REM FETCH WEATHER
3010 GOTO 100
4000 HOME
4005 MAXSTR = 0
4010 RA = AA +1
4015 GOSUB 11000
4020 TEMP$ = RS$
4025 RA = RA + LEN(RS$) +1
4030 GOSUB 11000
4035 FOOM$ = RS$
4040 RA = RA + LEN(RS$) +1
4045 GOSUB 11000
4050 WSPEED$ = RS$
4055 RA = RA + LEN(RS$) +1
4060 GOSUB 11000
4065 WDIR$ = RS$
4070 RA = RA + LEN(RS$) +1
4075 GOSUB 11000
4080 WD1$ = RS$
4085 RA = RA + LEN(RS$) +1
4090 GOSUB 11000
4095 WD2$ = RS$
4150 PRINT
4155 PRINT CITY$ +"/" +CC$ +" " +WD1$
4160 PRINT "-----------------------------"
4165 PRINT "TEMP: " +TEMP$ +"K"
4170 PRINT "HUMIDITY: " +FOOM$ +"%"
4175 PRINT "WIND SPEED: " +WSPEED$ +" m/s"
4177 REM PRINT
4180 REM PRINT WD1$ + ", " + WD2$
4500 GOTO 100
10000 REM WRITE WS$ TO WA
10010 FOR N = 0 TO LEN(WS$) -1
10020 P = WA +N
10030 C$ = MID$ (WS$,N +1,1)
10040 REM PRINT C$, ASC (C$)
10050 POKE P, ASC(C$)
10060 NEXT N
10070 POKE P +1,0
10080 RETURN
11000 REM ============ WRITE STRING TO RAM =================
11001 REM RA ADDRESS TO START READ
11002 REM MAXSTR IS LIMIT TO STR SIZE WE READ
11020 IF MAXSTR = 0 THEN MAXSTR = 250
11040 RS$ = ""
11060 FOR N = 0 TO MAXSTR
11080 P = RA +N
11100 C = PEEK(P)
11120 IF C = 0 THEN GOTO 11200
11140 RS$ = RS$ + CHR$(C)
11160 REM PRINT N+1,P,C, CHR$ (C)
11180 NEXT N
11200 RETURN

View File

@ -0,0 +1,18 @@
diskname='15_fixed_essid_weather-cc65.dsk'
echo "-------------------------"
echo "Files on disk image (before):"
java -jar ~/bin/AppleCommander.jar -l $diskname
for f in *.BAS
do
echo "-------------------------"
echo Removing file: $f
java -jar ~/bin/AppleCommander.jar -d $diskname $f
echo Adding file: $f
java -jar ~/bin/AppleCommander.jar -bas $diskname $f < $f
done
echo "-------------------------"
echo "Files on disk image (after):"
java -jar ~/bin/AppleCommander.jar -l $diskname

View File

@ -0,0 +1,4 @@
# Very simple Apple II Internet weather client example
* Use the arduino-cli or ide to transfer `../15_fixed_essid_weather-arduino/15_fixed_essid_weather-arduino.ino` to the ESP32 on the apple2idiot card.
* Use `apple2-cc65/weather.dsk` on your Apple ][.

View File

@ -0,0 +1,47 @@
10 CA = 49664
20 AA = CA +1
30 CC$ = ""
35 CITY$ = ""
100 PRINT
110 PRINT "----"
120 PRINT "MENU"
130 PRINT "(1) COUNTRY","",CC$
140 PRINT "(2) CITY","",CITY$
150 PRINT "(3) FETCH WEATHER"
160 PRINT "(4) SHOW WEATHER"
170 PRINT "(0) QUIT"
175 PRINT
180 INPUT "SELECT: ";S
190 IF S >4 THEN GOTO 100
200 IF S = 0 THEN END
210 IF S = 1 THEN GOTO 1000
220 IF S = 2 THEN GOTO 2000
230 IF S = 3 THEN GOTO 3000
240 IF S = 4 THEN GOTO 4000
250 GOTO 100
1000 INPUT "COUNTRY CODE: ";CC$
1010 WS$ = CC$
1020 WA = AA +1
1030 GOSUB 10000
1040 POKE AA,200
1050 GOTO 100
2000 INPUT "CITY: ";CITY$
2010 WS$ = CITY$
2020 WA = AA +1
2030 GOSUB 10000
2040 POKE AA,201
2050 GOTO 100
3000 POKE AA,205
3010 GOTO 100
4000 REM
4010 REM
4020 GOTO 100
10000 REM WRITE WS$ TO WA
10010 FOR N = 0 TO LEN(WS$) -1
10020 P = WA +N
10030 C$ = MID$ (WS$,N +1,1)
10040 PRINT C$, ASC(C$)
10050 POKE P, ASC(C$)
10060 NEXT N
10070 POKE P +1,3
10080 RETURN

View File

@ -0,0 +1,2 @@
100 CA = 49665
150 POKE CA,128

View File

@ -0,0 +1,2 @@
100 CA = 49665
150 POKE CA,111

View File

@ -0,0 +1,14 @@
100 CA = 49664: REM CARD ADDRESS 0XCN0
120 AA = CA +1: REM APPL CMD ADDRESS
140 ESPA = CA: REM ESP CMD ADDRESS
150 MAXSTR = 20
160 S$ = ""
170 INPUT "ENTER STRING: ";A$
200 FOR N = 0 TO LEN(A$) -1
210 P = CA +2 +N
215 P = CA +2 +N
220 C$ = MID$ (A$,N +1,1)
230 PRINT C$, ASC(C$)
240 POKE P, ASC(C$)
350 NEXT N
360 POKE P +1,3

View File

@ -0,0 +1,9 @@
100 CA = 49664: REM CARD ADDRESS 0XCN0
120 AA = CA +1: REM APPL CMD ADDRESS
140 ESPA = CA: REM ESP CMD ADDRESS
150 MAX = 42
200 FOR N = 0 TO MAX
215 P = CA +N
220 C = PEEK(P)
245 PRINT P,C, CHR$(C)
250 NEXT N

View File

@ -0,0 +1,41 @@
100 CA = 49664: REM CARD ADDRESS 0XCN0
120 AA = CA +1: REM APPL CMD ADDRESS
140 ESPA = CA: REM ESP CMD ADDRESS
150 MAXSTR = 22: REM TO LIMIT GOING BEZERK
160 NAP = PEEK(CA +3): REM #ACCESS POINTS
165 OFF = CA +4: REM ADDRESS OFFSET
167 PRINT ""
168 PRINT "AP #","ACCESS POINT"
169 PRINT "----","-------------------"
170 FOR J = 0 TO NAP
171 S$ = ""
200 FOR N = 0 TO MAXSTR
215 P = N +OFF
220 C = PEEK(P)
230 IF C = 3 THEN GOTO 400
240 S$ = S$ + CHR$(C)
245 REM PRINT N+1,P,C, CHR$ (C)
250 NEXT N
400 PRINT J +1,S$
420 OFF = P +1
450 NEXT J
590 PRINT ""
600 INPUT "SELECT WIFI AP #:";APN
620 INPUT "PASSWORD (BLANK IF NONE): ";PASS$
630 POKE AA +1,APN
640 WS$ = PASS$
645 WA = AA +2
650 GOSUB 2000
700 POKE AA,112: REM TELL ESP TO USE AP
1066 END
1900 REM ##### SUBS #######
2000 REM WRITE WS$ TO WA
2100 IF LEN(WS$) = 0 THEN GOTO 2360
2200 FOR N = 0 TO LEN(WS$) -1
2210 P = WA +N
2220 C$ = MID$ (WS$,N +1,1)
2230 REM PRINT C$, ASC (C$)
2240 POKE P, ASC(C$)
2350 NEXT N
2360 POKE P +1,3
2370 RETURN

View File

@ -0,0 +1,10 @@
100 CA = 49664: REM CARD ADDRESS 0XCN0
120 AA = CA +1: REM APPL CMD ADDRESS
140 ESPA = CA: REM ESP CMD ADDRESS
150 MAX = 21
215 P = CA +2
220 C1 = PEEK(P)
221 C2 = PEEK(P +1)
222 C3 = PEEK(P +2)
223 C4 = PEEK(P +3)
245 PRINT STR$(C1) +"." + STR$(C2) +"." + STR$(C3) +"." + STR$(C4)

View File

@ -0,0 +1,13 @@
11000 REM ============ WRITE STRING TO RAM =================
11001 REM RA ADDRESS TO START READ
11002 REM MAXSTR IS LIMIT TO STR SIZE WE READ
11020 IF MAXSTR = 0 THEN MAXSTR = 250
11040 RS$ = ""
11060 FOR N = 0 TO MAXSTR
11080 P = RA +N
11100 C = PEEK(P)
11120 IF C = 3 THEN GOTO 400
11140 S$ = S$ + CHR$(C)
11160 REM PRINT N+1,P,C, CHR$ (C)
11180 NEXT N
11200 RETURN

View File

@ -0,0 +1,9 @@
10000 REM WRITE WS$ TO WA
10010 FOR N = 0 TO LEN(WS$) -1
10020 P = WA +N
10030 C$ = MID$ (WS$,N +1,1)
10040 PRINT C$, ASC(C$)
10050 POKE P, ASC(C$)
10060 NEXT N
10070 POKE P +1,3
10080 RETURN

View File

@ -0,0 +1,14 @@
100 CA = 49664: REM CARD ADDRESS 0XCN0
120 AA = CA +1: REM APPL CMD ADDRESS
140 ESPA = CA: REM ESP CMD ADDRESS
150 MAXSTR = 20
160 S$ = ""
170 INPUT "ENTER STRING: ";A$
200 FOR N = 0 TO LEN(A$) -1
210 P = CA +2 +N
215 P = CA +2 +N
220 C$ = MID$ (A$,N +1,1)
230 PRINT C$, ASC(C$)
240 POKE P, ASC(C$)
350 NEXT N
360 POKE P +1,3

View File

@ -1,6 +0,0 @@
# Apple2 Internet Weather Client Example
* Use the arduino-cli or ide to transfer weather.ino to the ESP32 on the apple2idiot card.
* Use either `WEATHER.BAS` or the `/apple2-cc65/weather.dsk` on your Apple ][.