|
Forum Index : Microcontroller and PC projects : Wolfram Alpha on Webmite
| Author | Message | ||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Hi Everybody! I just want to try this API with Webmite: https://api.wolframalpha.com/v1/result?appid=myappidhere&i=How+far+is+Los+Angeles+from+New+York%3f It is a sample query, I have my appid. Can anybody help how to start it? Is it possible with Webmite TLS connection? I tried to build up something, but I got error. Thanks a lot! G@bor |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11435 |
Update the firmware to this: WebMiteRP2350V6.03.00RC16.zip Join the lines making up the request Dim buff%(4096/8) Dim CRLF$ = Chr$(13) + Chr$(10) Dim b$ = "GET /v1/result?appid=myappid&i=How+far+is+Los+Angeles+from+New+York%3f HTTP/1.1" Inc b$,CRLF$+ "Host: api.wolframalpha.com" + CRLF$+ "User-Agent: WebMite" + CRLF$ Inc b$, "Accept: text/plain" + CRLF$+ "Connection: close" + CRLF$ + CRLF$ Print b$ WEB OPEN TLS CLIENT "api.wolframalpha.com", 443 WEB TCP CLIENT REQUEST b$, buff%(), 20000 Pause 1000 LongString print buff%() WEB CLOSE TCP CLIENT Edited 2026-06-06 02:27 by matherp |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Peter! Thanks. I exactly did this, I got this error during open the client; Error: TLS client error -15 G@bor |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11435 |
Try again with firmware just posted |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
With RC16? |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11435 |
Above in this thread - my first post |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Yes, clear. I updated. Just trying G@bor |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Peter! Many thanks it is working! What caused this error? G@bor |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11435 |
RSA hadn't been enabled as an encryption method |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Very good! So it will upgrade in the following versions? G@bor |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 11435 |
Yes Try this ' Wolfram Alpha "short answer" client for WebMite. ' Prompts for an English-language question, sends it to the v1/result ' endpoint over TLS, prints whatever the server returns as the answer body. ' ' Requires: ' - WebMite firmware with TLS enabled (RP2350) ' - WiFi already configured and connected ' - Your own Wolfram AppID replace APPID$ below option web messages off Const APPID$ = "myid" Const HOST$ = "api.wolframalpha.com" Const CRLF$ = Chr$(13) + Chr$(10) Dim buff%(8192/8) Dim question$ Print "Wolfram Alpha client blank line to quit" Do Line Input "Ask: ", question$ If question$ = "" Then Exit Do Print Ask$(question$) Loop End ' -------------------------------------------------------------------------- ' Ask$ send one question, return the answer body (or an error string) ' -------------------------------------------------------------------------- Function Ask$(q$) Local req$, Integer hdr_end req$ = "GET /v1/result?appid=" + APPID$ + "&i=" + UrlEncode$(q$) + " HTTP/1.1" + CRLF$ Cat req$, "Host: " + HOST$ + CRLF$ Cat req$, "User-Agent: WebMite" + CRLF$ Cat req$, "Accept: text/plain" + CRLF$ Cat req$, "Connection: close" + CRLF$ + CRLF$ LongString clear buff%() On Error Skip 1 WEB OPEN TLS CLIENT HOST$, 443, 15000 If MM.Errno <> 0 Then Ask$ = "[connection failed: " + MM.ErrMsg$ + "]" Exit Function EndIf WEB TCP CLIENT REQUEST req$, buff%(), 15000 Pause 1000 WEB CLOSE TCP CLIENT ' Split headers from body at the blank line (CRLF CRLF). hdr_end = LInStr(buff%(), CRLF$ + CRLF$) If hdr_end = 0 Then Ask$ = "[malformed response]" Exit Function EndIf Ask$ = LGetStr$(buff%(), hdr_end + 4, LLen(buff%()) - hdr_end - 3) End Function ' -------------------------------------------------------------------------- ' UrlEncode$ percent-encode a string for use in a URL query value ' -------------------------------------------------------------------------- Function UrlEncode$(s$) Local Integer i, c Local out$ For i = 1 To Len(s$) c = Asc(Mid$(s$, i, 1)) Select Case c Case 48 To 57, 65 To 90, 97 To 122 ' 0-9 A-Z a-z Cat out$, Chr$(c) Case 45, 46, 95, 126 ' - . _ ~ Cat out$, Chr$(c) Case 32 ' space -> '+' Cat out$, "+" Case Else ' everything else -> %XX Cat out$, "%" + RIGHT$("0" + HEX$(c), 2) End Select Next i UrlEncode$=out$ End Function Edited 2026-06-06 02:53 by matherp |
||||
| terekgabor Regular Member Joined: 02/01/2026 Location: HungaryPosts: 90 |
Peter! That is I planned to integrate! Very cool. Thanks again for support! I like this programming language very much, and what you are doing is brilliant. G@bor |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |