The main goal is to be able to send and receive commands (only simple text commands) to/from the iPhone to/from my digital mixer (Soundcraft Ui24R).
I'm using this example from @Erel. An example of text command is: "SETD^i.11.mute^1"
When I start the app and press "Connect", the app connects to the mixer, and retrieves values that the mixer sends initially. This continues for 20 seconds before the connection is broken.
1) PROBLEM 1:
The values that are retrieved from mixer in the initialization process, I read in the log as an error:
Text Message Error:
<B4IExceptionWrapper: Error Domain=caught_exception Code=0
"Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840
"JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0."
UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0}"
UserInfo={NSLocalizedDescription=Error parsing string: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0."
UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set. around line 1, column 0., NSJSONSerializationErrorIndex=0}}>
The error occurs in the line highlighted in the code below (WebSocketHandler Class module):
B4X:
Private Sub ws_TextMessage(msg As String)
Try
Dim jp As JSONParser
jp.Initialize(msg)
Dim m As Map = jp.NextObject [COLOR=rgb(184, 49, 47)]' ************* THIS IS WHERE THE ERROR OCCURS[/COLOR]
Dim etype As String = m.get("etype")
Dim params As List = m.get("value")
Dim event As String = m.get("prop")
If etype = "runFunction" Then
CallSub2(CallBack, EventName & "_" & event, params)
Else If etype = "runFunctionWithResult" Then
Dim data As Map = CallSub2(CallBack, EventName & "_" & event, params)
Dim jg As JSONGenerator
jg.Initialize(CreateMap("type": "data", "data": data))
ws.SendText(jg.ToString)
End If
Catch
Log("TextMessage Error: " & LastException) [COLOR=rgb(184, 49, 47)] ' ************* THE ERROR IS WRITTEN TO THE LOG...[/COLOR]
End Try
End Sub
I know the app tries to retrieve a JSON text, which the mixer does not send.
So - if I replace the "Try/Catch/End Try" code with Log(msg) I get what I'm looking for - for example:
SETD^a.6.dyn.ratio^1
SETD^a.6.gate.enabled^1
SETD^a.6.dyn.release^0.4887695312
SETD^a.6.dyn.outgain^0.3334960938
SETD^a.6.gate.thresh^0
SETD^a.6.gate.attack^0
I'm happy with that BUT....
2) PROBLEM 2:
When I change the settings on the mixer (e.g. volume), the mixer sends out text codes that I can read in the developer module in the Edge browser (se the picture...)
But the B4i app does not register any of the changes!
(You can se a demo of the digital mixer from Soundcraft here)
3) PROBLEM 3:
As long as I have a contact with the mixer, I try to send an "ALIVE" text code, or a text code such as "SETD^i.11.mute^1") to the mixer. This is handled in this part of the code (WebSocketHandler Class module):...
B4X:
Public Sub SendEventToServer(Event As String, Data As Map)
Dim m As Map
m.Initialize
m.Put("type", "event")
m.Put("event", Event)
m.Put("params", Data)
Dim jg As JSONGenerator
jg.Initialize(m)
ws.SendText(jg.ToString)
End Sub
...and here is the MAIN PROBLEM. Nothing happens!...
The mixer does not seem to receive the correct text code, nor does the mixer send any response back. Nothing happens...
I know this sends a JSON text and the mixer doesn't handle this. Therefore I tried to send a plain text, for example:
B4X:
ws.SendText("SETD^i.11.mute^1")
...but the mixer doesn't register any of this...
In the Edge browser developer module, I send the same text command - which works great (se the picture abowe).
Sooo:...
I hope that this can be sufficiently explained - to solve the problem?...
Last edited: