Raspberry BASIC

Author Topic: RPI Zero Portable  (Read 315 times)

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 217
    • View Profile
    • ScriptBasic
RPI Zero Portable
« on: March 06, 2021, 09:20:26 pm »
I picked up a dongle like adapter for my RPi Zero running Raspian Lite. This gives me a USB portable Linux I connect to via WIFI / SSH.


PS C:\WINDOWS\system32> ssh pi@192.168.0.193
pi@192.168.0.193's password:
Linux raspberrypi 5.10.17+ #1403 Mon Feb 22 11:26:13 GMT 2021 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Mar  6 13:01:58 2021 from 192.168.0.191
pi@raspberrypi:~ $

pi@raspberrypi:~ $ free --mega
              total        used        free      shared  buff/cache   available
Mem:            450         110          93           7         246         278
Swap:           104           3         101
pi@raspberrypi:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       117G  1.8G  111G   2% /
devtmpfs        183M     0  183M   0% /dev
tmpfs           216M     0  216M   0% /dev/shm
tmpfs           216M  3.1M  213M   2% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           216M     0  216M   0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   48M  205M  19% /boot
tmpfs            44M     0   44M   0% /run/user/1000
pi@raspberrypi:~ $


Installed:

  • ScriptBasic source and runtime
  • MySQL (MariaDB) Server
  • Apache2 Web Server (running on WIFI connection)
« Last Edit: March 07, 2021, 06:25:47 pm by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 217
    • View Profile
    • ScriptBasic
Re: RPI Zero Portable
« Reply #1 on: March 07, 2021, 05:57:00 am »
Mapping Network Drive Over SSH in Windows

SSHFS (SSH Filesystem) is a filesystem client to mount and interact with directories and files located on a remote server or workstation over a normal ssh connection. The client interacts with the remote file system via the SSH File Transfer Protocol (SFTP), a network protocol providing file access, file transfer, and file management functionality over any reliable data stream that was designed as an extension of the Secure Shell protocol (SSH) version 2.0.

Makerlab Web Site (Free & Open Source)

The attached screen shot is my Windows 10 file explorer mapped (drive R:) to my home directory of my dongle RPi Zero.
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 217
    • View Profile
    • ScriptBasic
Re: RPI Zero Portable
« Reply #2 on: March 07, 2021, 06:12:35 pm »
I install PHP 7.3 for Apache and phpMyAdmin. With my RPi mapped drive I can use UltraEdit on my Windows laptop. Running Raspian Lite seems to make the RPi Zero run efficiently. I think I've created a nice Linux sidekick for my Windows 10 laptop.  8)
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 217
    • View Profile
    • ScriptBasic
Re: RPI Zero Portable
« Reply #3 on: March 07, 2021, 09:40:05 pm »
This is an example of using the MySQL extension module with ScriptBasic on the RPi Zero.

Code: Script BASIC
  1. ' MySQL Demo Program
  2.  
  3. INCLUDE mysql.bas
  4.  
  5. dbh = mysql::RealConnect("localhost","root","mypswd","classicmodels")
  6. mysql::query(dbh,"SELECT * FROM products WHERE productLine = 'Classic Cars'")
  7.  
  8. WHILE mysql::FetchHash(dbh,column)
  9.   PRINT column{"productCode"}," - ",column{"productName"}," - ",FORMAT("%~$###.00~",column{"MSRP"}),"\n"
  10. WEND
  11.  
  12. PRINTNL
  13. PRINT "The database handle is: ",dbh,"\n"
  14. PRINT "Affected rows by SELECT: ",mysql::AffectedRows(dbh),"\n"
  15. PRINT "Character set name is: ",mysql::CharacterSetName(dbh),"\n"
  16. PRINT "Last error is: ",mysql::ErrorMessage(dbh),"\n"
  17. PRINT "Client info is: ",mysql::GetClientInfo(),"\n"
  18. PRINT "Host info is: ",mysql::GetHostInfo(dbh),"\n"
  19. PRINT "Proto info is: ",mysql::GetProtoInfo(dbh),"\n"
  20. PRINT "Server info is: ",mysql::GetServerInfo(dbh),"\n"
  21. PRINT "PING result: ",mysql::Ping(dbh),"\n"
  22. PRINT "Thread ID: ",mysql::ThreadId(dbh),"\n"
  23. PRINT "Status is: ",mysql::Stat(dbh),"\n"
  24.  
  25. mysql::Close(dbh)
  26.  


pi@raspberrypi:~/sb/examples $ scriba mysql_demo.sb
S10_1949 - 1952 Alpine Renault 1300 - $214.30
S10_4757 - 1972 Alfa Romeo GTA - $136.00
S10_4962 - 1962 LanciaA Delta 16V - $147.74
S12_1099 - 1968 Ford Mustang - $194.57
S12_1108 - 2001 Ferrari Enzo - $207.80
S12_3148 - 1969 Corvair Monza - $151.08
S12_3380 - 1968 Dodge Charger - $117.44
S12_3891 - 1969 Ford Falcon - $173.02
S12_3990 - 1970 Plymouth Hemi Cuda - $ 79.80
S12_4675 - 1969 Dodge Charger - $115.16
S18_1129 - 1993 Mazda RX-7 - $141.54
S18_1589 - 1965 Aston Martin DB5 - $124.44
S18_1889 - 1948 Porsche 356-A Roadster - $ 77.00
S18_1984 - 1995 Honda Civic - $142.25
S18_2238 - 1998 Chrysler Plymouth Prowler - $163.73
S18_2870 - 1999 Indy 500 Monte Carlo SS - $132.00
S18_3232 - 1992 Ferrari 360 Spider red - $169.34
S18_3233 - 1985 Toyota Supra - $107.57
S18_3278 - 1969 Dodge Super Bee - $ 80.41
S18_3482 - 1976 Ford Gran Torino - $146.99
S18_3685 - 1948 Porsche Type 356 Roadster - $141.28
S18_4027 - 1970 Triumph Spitfire - $143.62
S18_4721 - 1957 Corvette Convertible - $148.80
S18_4933 - 1957 Ford Thunderbird - $ 71.27
S24_1046 - 1970 Chevy Chevelle SS 454 - $ 73.49
S24_1444 - 1970 Dodge Coronet - $ 57.80
S24_1628 - 1966 Shelby Cobra 427 S/C - $ 50.31
S24_2766 - 1949 Jaguar XK 120 - $ 90.87
S24_2840 - 1958 Chevy Corvette Limited Edition - $ 35.36
S24_2887 - 1952 Citroen-15CV - $117.44
S24_2972 - 1982 Lamborghini Diablo - $ 37.76
S24_3191 - 1969 Chevrolet Camaro Z28 - $ 85.61
S24_3371 - 1971 Alpine Renault 1600s - $ 61.23
S24_3432 - 2002 Chevy Corvette - $107.08
S24_3856 - 1956 Porsche 356A Coupe - $140.43
S24_4048 - 1992 Porsche Cayenne Turbo Silver - $118.28
S24_4620 - 1961 Chevrolet Impala - $ 80.84
S700_2824 - 1982 Camaro Z28 - $101.15

The database handle is: 1
Affected rows by SELECT: 38
Character set name is: latin1
Last error is:
Client info is: 10.3.27
Host info is: Localhost via UNIX socket
Proto info is: 10
Server info is: 10.3.27-MariaDB-0+deb10u1
PING result: -1
Thread ID: 0
Status is: Uptime: 8093  Threads: 8  Questions: 486  Slow queries: 0  Opens: 31  Flush tables: 1  Open tables: 25  Queries per second avg: 0.060
pi@raspberrypi:~/sb/examples $

« Last Edit: March 07, 2021, 09:51:21 pm by John Spikowski »
ScriptBasic Project Manager/Facilitator

John Spikowski

  • BASIC Developer
  • ***
  • Posts: 217
    • View Profile
    • ScriptBasic
Re: RPI Zero Portable
« Reply #4 on: March 08, 2021, 04:58:49 am »
This is an example of using the OpenWeather API with Curl and the ScriptBasic LIKE function to parse the returned JSON response.

Note: I dislike the ScriptBasic function name JOKER().

Code: Script BASIC
  1. ' OpenWeather - Curl Example
  2.  
  3. IMPORT curl.bas
  4.  
  5. FUNCTION MATCH(segment)
  6.   MATCH = JOKER(segment)
  7. END FUNCTION
  8.  
  9. place = COMMAND()
  10.  
  11. ch = curl::init()
  12. curl::option(ch, "URL", "http://api.openweathermap.org/data/2.5/weather?q=" & place & "&units=imperial&appid=72405563bf538d7ce629baf2a9766e70")
  13. curl::option(ch, "CUSTOMREQUEST", "GET")
  14. response = curl::perform(ch)
  15. curl::finish(ch)
  16.  
  17. PRINT "\n", response,"\n\n"
  18.  
  19. IF response LIKE "*lon\":*,\"lat\":*}*temp\":*,*pressure\":*,*humidity\":*}*dt\":*,*country\":\"*\"*timezone\":*,*name\":\"*\"*" THEN
  20.   PRINT "Country:    ", MATCH(13), "\n"
  21.   PRINT "City:       ", MATCH(17), "\n"
  22.   PRINT "Longitude:  ", MATCH(2), "\n"
  23.   PRINT "Latitude:   ", MATCH(3), "\n"
  24.   PRINT "Date/Time:  ", FORMATDATE("MM/DD/YEAR 0H:0m:0s", MATCH(11) + MATCH(15)), "\n"
  25.   PRINT "Tempreture: ", MATCH(5), " F\n"
  26.   PRINT "Pressure:   ", MATCH(7), " hPa\n"
  27.   PRINT "Humidity:   ", MATCH(9), " %\n"
  28. END IF
  29.  


pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb Anacortes,US

{"coord":{"lon":-122.6127,"lat":48.5126},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":45.27,"feels_like":34.83,"temp_min":42.01,"temp_max":48.2,"pressure":1016,"humidity":53},"visibility":10000,"wind":{"speed":11.5,"deg":60},"clouds":{"all":1},"dt":1615229908,"sys":{"type":1,"id":3524,"country":"US","sunrise":1615214245,"sunset":1615255505},"timezone":-28800,"id":5785657,"name":"Anacortes","cod":200}

Country:    US
City:       Anacortes
Longitude:  -122.6127
Latitude:   48.5126
Date/Time:  3/8/2021 10:58:28
Tempreture: 45.27 F
Pressure:   1016 hPa
Humidity:   53 %

real    0m0.437s
user    0m0.091s
sys     0m0.073s
pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb New York,US

{"coord":{"lon":-74.006,"lat":40.7143},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01d"}],"base":"stations","main":{"temp":40.05,"feels_like":30.9,"temp_min":37.4,"temp_max":42.8,"pressure":1030,"humidity":26},"visibility":10000,"wind":{"speed":5.75,"deg":0},"clouds":{"all":1},"dt":1615229912,"sys":{"type":1,"id":4610,"country":"US","sunrise":1615202327,"sunset":1615244097},"timezone":-18000,"id":5128581,"name":"New York","cod":200}

Country:    US
City:       New York
Longitude:  -74.006
Latitude:   40.7143
Date/Time:  3/8/2021 13:58:32
Tempreture: 40.05 F
Pressure:   1030 hPa
Humidity:   26 %

real    0m0.332s
user    0m0.120s
sys     0m0.049s
pi@raspberrypi:~/sb/examples $ time scriba curlweather.sb London,GB

{"coord":{"lon":-0.1257,"lat":51.5085},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04n"}],"base":"stations","main":{"temp":46.92,"feels_like":42.51,"temp_min":45,"temp_max":48.2,"pressure":1022,"humidity":53},"visibility":10000,"wind":{"speed":1.14,"deg":0},"clouds":{"all":100},"dt":1615230315,"sys":{"type":1,"id":1414,"country":"GB","sunrise":1615185018,"sunset":1615225950},"timezone":0,"id":2643743,"name":"London","cod":200}

Country:    GB
City:       London
Longitude:  -0.1257
Latitude:   51.5085
Date/Time:  3/8/2021 19:05:15
Tempreture: 46.92 F
Pressure:   1022 hPa
Humidity:   53 %

real    0m0.333s
user    0m0.111s
sys     0m0.053s
pi@raspberrypi:~/sb/examples $

« Last Edit: March 09, 2021, 04:57:43 am by John Spikowski »
ScriptBasic Project Manager/Facilitator