Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 19:30 26 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Fruitoftheshed giving me 404

     Page 5 of 5    
Author Message
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3150
Posted: 08:19pm 17 Jan 2024
Copy link to clipboard 
Print this post

Ok, proof-of-concept for folder and file retrieval from github.

Here's an ESP32-S2Mini plugged into a picomite--pins 1 and 2 on the picomite connected to 14 and 13 on the ESP, and 40 (5V) and 38 (0V) to 5V and 0V on the ESP. Power supplied to the Picomite by USB also powers the S2Mini.

Of course, an S2Mini could be connected to picomite PCBs using other available pins, or to a CMM2 or an F4. This implementation is for github-based program files and folders, but similar retrieval is possible from other sources and, one hopes, from Docu-Wiki (although most of the FotS pages are not just program listings).

There's little error checking in this, and presumably, if useful, some sort of folder display such as Jiri's CMM2.fun NC program would be needed.

This would only be specifically useful for 'Mites for which there was not a PC handy.



Running the program below (TeraTerm screen):
> files
A:/
  <DIR>  .
  <DIR>  ..
00:00 01-01-2000          4  bootcount
00:39 01-01-2000        516  g1.bas
14:34 17-01-2024       1553  g2.bas
00:06 01-01-2000        118  getdir.bas
2 directories, 4 files, 782336 bytes free
> load "g2.bas"
>   RUN
Trying GETDIR https://github.com/lyzby/FOTS-demo/tree/main/MMBLibrary
Trying GETDIR https://github.com/lyzby/FOTS-demo/tree/main/MMBLibrary/CAPico
Trying GETFIL https://raw.githubusercontent.com/lyzby/FOTS-demo/main/MMBLibrary/CAPico/capico.bas
'OPTION EXPLICIT  ' all variables must be defined before use
Trying GETFIL https://raw.githubusercontent.com/lyzby/FOTS-demo/main/MMBLibrary/REVERSE.BAS
10 PRINT TAB(32);"REVERSE"
> files
A:/
  <DIR>  .
  <DIR>  ..
00:00 01-01-2000          4  bootcount
14:36 17-01-2024      28947  capico.bas
14:36 17-01-2024        175  CAPico.dir
00:39 01-01-2000        516  g1.bas
14:34 17-01-2024       1553  g2.bas
00:06 01-01-2000        118  getdir.bas
14:36 17-01-2024       1196  MMBLibrary.dir
14:36 17-01-2024       2085  REVERSE.BAS
2 directories, 8 files, 741376 bytes free


The program downloads the items in the folder MMBLibrary, which contains 79 files and one folder, CAPico. MMBLibrary.dir contains lines with item name and type ("F" or "D"). The program next downloads the items in the subfolder CAPico. It then downloads a file from the CAPico folder, capico.bas, and then from the MMBLibrary folder, REVERSE.BAS.

Here's what it looks like on the Annex side:



Picomite code:
Dim integer inbuf(5000) ' longstring buffer for return
crlf$=Chr$(13)+Chr$(10)
SetPin 2,1,com1 ' rx,tx
Open "com1:115200,20000" As #1
sReqPath$="/lyzby/FOTS-demo/tree/main/MMBLibrary"
sReqPathF$="/lyzby/FOTS-demo/main/MMBLibrary"
sReqDir$="https://github.com"
sReqFile$="https://raw.githubusercontent.com"
For l=1 To 4
 If l=1 Then: sRequest$="GETDIR "+sReqDir$+sReqPath$
 ElseIf l=2 Then: sRequest$="GETDIR "+sReqDir$+sReqPath$+"/CAPico"
 ElseIf l=3 Then: sRequest$="GETFIL "+sReqFile$+sReqPathF$+"/CAPico/capico.bas"
 ElseIf l=4 Then: sRequest$="GETFIL "+sReqFile$+sReqPathF$+"/REVERSE.BAS"
 EndIf
 Print "Trying "+sRequest$
 githubGet
 Pause 1000
Next l
End

Sub githubGet
 Print #1,sRequest$
 Do : Loop While Loc(#1)=0
 Pause 100 ' let characters arrive on COM1
 LongString Clear inbuf()
 Do
   LongString append inbuf(),Input$(Min(255,Loc(#1)),#1)
   Pause 50
 Loop While Loc(#1)>0
 If Mid$(sRequest$,1,6)="GETFIL" Then
   i=LInStr(inbuf(),Chr$(10))
   If i>0 And i<256 Then: a$=LGetStr$(inbuf(),1,i-1)
   Else : a$=LGetStr$(inbuf(),1,22)
   EndIf
   Print a$
 EndIf
'  LongString Print inbuf()
 i=Instr(sRequest$,"/") ' extract the file/dir name, after last "/"
 k=0
 Do While i>0
   k=i
   i=Instr(i+1,sRequest$,"/")
 Loop
 If k>0 Then
   sFile$=Mid$(sRequest$,k+1) ' extract folder or file name
   If Mid$(sRequest$,1,6)="GETDIR" Then sFile$=sFile$+".dir"
   Open sFile$ For output As #2
   LongString Print #2,inbuf()
   Close #2
 EndIf
End Sub ' githubGet


And the Annex code:
' getFilesJSON.bas
dim itemName$(200)
dim itemType$(200)
crlf$=chr$(13)+chr$(10)
qt$=chr$(34)
source$="github" ' http dropbox onedrive blob
url$="192.168.1.82/files/"
url$="https://github.com/lyzby/FOTS-demo/tree/main/MMBLibrary"
getType$="folder"
serial2.mode 115200,13,14 ' tx,rx
onserial2 getRequest
wlog "Waiting for input"
'gosub getRequest
do
loop

getRequest:
 pause 200 ' plenty of time to receive entire request
 sRequest$=serial2.input$
 i=instr(sRequest$,crlf$)
 if i>0 then
   sRequest$=mid$(sRequest$,1,i-1)
 endif
 wlog sRequest$
 if mid$(sRequest$,1,6)="GETDIR" then
   url$=mid$(sRequest$,8)
   sFiles$=""
   nFiles=0
   gosub getFilesJSON
   wlog "# files: "+str$(nFiles)
   if nFiles>0 then
     sFiles$=""
     for i=0 to nFiles-1
       sFiles$=sFiles$+itemName$(i)+","+itemType$(i)+crlf$
'        wlog str$(i+1)+" "+itemName$(i)+","+itemType$(i)
     next i
     print2 sFiles$
   endif
 elseif mid$(sRequest$,1,6)="GETFIL" then
   url$=mid$(sRequest$,8)
'    wlog url$
   a$=wget$(url$,80)
   i=instr(a$,"Not Found")
   if i>0 then
     a$=mid$(a$,1,i+9)
     wlog a$+" "+url$
   else ' OK--strip off header
'      i=instr(a$,crlf$+crlf$)
     i=instr(a$,chr$(10)+chr$(10))
     if i>0 then
       a$=mid$(a$,i+2)
       i=instr(a$,chr$(10))
       wlog mid$(a$,1,i-1) ' first line
     endif
   endif
   print2 a$
 endif
 wlog "Waiting for input"
 return  

getFilesjson:
   a$=wget$(url$,80)
'    wlog "Returned :"+a$
   if source$="github" then
     j=instr(1,a$,"""tree"":{""items""") ' find start of array of files
'      j=instr(1,a$,"{""items"";[") ' find start of array of files
     jEnd=instr(j,a$,"}]")        ' find end of array of files
     if j>0 and jEnd > j then
       c$="{"+mid$(a$,j+8,jEnd-j-6)+"}"
'        wlog c$
'        wlog str$(j)+" "+str$(jEnd)
       for i=1 to 999
'          fname$=json$(c$,"items[i].name")
         fname$=json$(c$,"items.name["+str$(i)+"]")
         if fname$="not found" then
           exit for
         endif
         itemName$(nFiles)=fname$
'          fType$=json$(c$,"items[i].contentType")
         fType$=json$(c$,"items.contentType["+str$(i)+"]")
         if fType$="file" then
           itemType$(nFiles)="F"
         elseif fType$="not found"
           itemType$(nFiles)="?"
         else
           itemType$(nFiles)=ucase$(mid$(fType$,1,1))
         endif
         nFiles=nFiles+1
         if nFiles>199 then
           exit for
         endif
       next i
     endif
'      if nFIles>1 then
'        nFiles=nFiles-1
'      endif
 return

PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
     Page 5 of 5    
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024