Thingsboard Knob Control using RPC call method keep getting the error, Unable to parse response: [object Object]. Set method works fine and only the get method at the start has this error. My message is as below and it looks fine to me. BTW - Switch control widgets works fine using the same code.
Topic: v1/devices/me/rpc/request/"id"
Message: {"method":"getValue","params":null}
Reply: {"Value":255}
if (methodName.equals("getValue")) {
String responseTopic = String(topic);
responseTopic.replace("request", "response");
mqtt.publish(responseTopic.c_str(), get_value().c_str());
}
String get_value() {
StaticJsonDocument<200> doc6;
doc6[String("Value")]=value;
char payload[200];
serializeJson(doc6, payload, sizeof(payload));
String strPayload = String(payload);
return strPayload;
}
I am using Arduino MKR Wifi 1010 to publish the MQTT response. Stuck on this for a long time. Any suggestion on how to fix this error? I do see the value reaches to the dashboard in the audit log. It seems like the knob control can not parse the json object. Is there any way to fix this in serializing the json object?
Anyone who wants an answer for this.
After testing many ways, I found that the reply sent to knob control do not need to be serialized or be an Json object. You can just send the plain number in string format. Example code below:
if (methodName.equals("getValue")) {
String responseTopic = String(topic);
responseTopic.replace("request", "response");
mqtt.publish(responseTopic.c_str(), get_value().c_str());
}
String get_value() {
String strPayload = String(GLONT);
return strPayload;
}
Related
I am new to HTMLUnit. I am trying to get information from a public site (given in the code below). While I can open this public url in Chrome browser or Chrome Selenium extension without error and continue functioning with it, my HTMLUnit program is throwing an error as below which it seems is stemming from a particular Javascript in the page. My question is, how to resolve this kind of problem ? I cannot disable the javascript altogether as the form section with details will not be available in that case. However if I use the command
EcmaError: lineNumber=[55] column=[0] lineSource=[] name=[TypeError] sourceName=[https://www.marutisuzuki.com/js/server_cookies.js] message=[TypeError: Cannot find function fetchServerCookie in object [object Object]. (https://www.marutisuzuki.com/js/server_cookies.js#55)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function fetchServerCookie in object [object Object]. (https://www.marutisuzuki.com/js/server_cookies.js#55)
String pageAsXml = null;
String pageAsText = null;
try{
WebClient webClient = new WebClient(BrowserVersion.CHROME);
HtmlPage page =
webClient.getPage("https://www.marutisuzuki.com/dealer-showrooms/");
//webClient.getOptions().setJavaScriptEnabled(false);
pageAsXml = page.asXml();
pageAsText = page.asNormalizedText();
System.out.println(pageAsText);
}
catch(Exception e) {
e.printStackTrace();
}
You can use
webClient.getOptions.setThrowExceptionOnScriptError(false);
For more have a look at https://htmlunit.sourceforge.io/javascript-howto.html.
BTW: this is an error in the page itself because you got the same in real browsers.
I'm trying to pass data via post method from my client to a server.
I'm using WebApi to do so.
This i the code i used:
client:
var client = new RestClient();
client.EndPoint = #"http://localhost:57363/hello";
client.Method = HttpVerb.POST;
client.PostData = "{value: Hello}";
var json = client.MakeRequest();
Console.WriteLine(json);
Console.Read();
server:
// POST api/<controller>
public string Post([FromBody]string value)
{
return value + ", world.";
}
The server responds as expected when using postman. However, the client passes a null value instead of the real value.
What am i doing wrong?
First of all a correct json would look like "{value: 'Hello'}".
I use json-online to easily validate such inline json.
On the other hand, I think that you should send just the value in this case, not the entire json (because you are trying to resolve a simple type,a string), so the client should send a request like:
client.PostData = "'Hello'";
According to the docs for the Native Client MediaStreamVideoTrack there is a constructor that "Constructs a MediaStreamVideoTrack that outputs given frames to a new video track, which will be consumed by Javascript."
My idéa was then to put frames into this video track, that can later be displayed by javascript in a video tag or passed to a RTCPeerConnection.
I don't know if do it correctly, but from the docs for PostMessage states that it should be supported to pass a resource. But with the simple Native Client code below I only get a warning in the browser console: "Failed to convert a PostMessage argument from a PP_Var to a Javascript value. It may have cycles or be of an unsupported type."
virtual void HandleMessage(const pp::Var& var_message) {
if (!var_message.is_dictionary()) {
LogToConsole(PP_LOGLEVEL_ERROR, pp::Var("Invalid message!"));
return;
}
pp::VarDictionary var_dictionary_message(var_message);
std::string command = var_dictionary_message.Get("command").AsString();
if (command == "create_track") {
pp::MediaStreamVideoTrack video_track = pp::MediaStreamVideoTrack::MediaStreamVideoTrack(this);
pp::VarDictionary dictionary;
dictionary.Set(pp::Var("track"), pp::Var(video_track));
PostMessage(dictionary);
}
}
Am I doing something wrong, or something that isn't just supported? :)
A MediaStreamVideoTrack can only be created by the page (not the plugin) and passed to the plugin by PostMessage. See this example code:
https://code.google.com/p/chromium/codesearch#chromium/src/ppapi/examples/media_stream_video/media_stream_video.cc
https://code.google.com/p/chromium/codesearch#chromium/src/ppapi/examples/media_stream_video/media_stream_video.html
So this code runs in an asp.net app on Linux. The code calls one of my services. (WCF doesn't work on mono currently, that is why I'm using asmx). This code works AS INTENDED when running from Windows (while debugging). As soon as I deploy to Linux, it stops working. I'm definitely baffled. I've tested the service thoroughly and the service is fine.
Here is the code producing an error: (NewVisitor is a void function taking 3 strings in)
//This does not work.
try
{
var client = new Service1SoapClient();
var results = client.NewVisitor(Request.UserHostAddress, Request.UrlReferrer == null ? String.Empty : Request.UrlReferrer.ToString(), Request.UserAgent);
Logger.Debug("Result of client: " + results);
}
Here is the error generated: Object reference not set to an instance of an object
Here is the code that works perfectly:
//This works (from the service)
[WebMethod(CacheDuration = _cacheTime, Description = "Returns a List of Dates", MessageName = "GetDates")]
public List<MySqlDateTime> GetDates()
{
return db.GetDates();
}
//Here is the code for the method above
var client = new Service1Soap12Client();
var dbDates = client.GetDates();
I'd love to figure out why it is saying that the object is not set.
Methods tried:
new soap client.
new soap client with binding and endpoint address specified
Used channel factory to create and open the channel.
If more info is needed I can give more. I'm out of ideas.
It looks like a bug in mono. You should file a bug with a reproducible test case so it can be fixed (and possibly find a workaround you can use).
Unfortunately, I don't have Linux to test it but I'd suggest you put the client variable in an using() statement:
using(var client = new Service1SoapClient())
{
var results = client.NewVisitor(Request.UserHostAddress, Request.UrlReferrer == null ?
String.Empty : Request.UrlReferrer.ToString(), Request.UserAgent);
Logger.Debug("Result of client: " + results);
}
I hope it helps.
RC.
I'd like to see what is about to be sent to the SQL Server from my SqlCommand before SQLCmd.ExecuteNonQuery() runs.
I'm trying to debug because I am receiving the following error: System.FormatException: Failed to convert parameter value from a String to a Int32.
Normally, I would use SQL Server Profiler to view what is being sent to SQL Server, but my statement is not making it that far.
Is there a way to determine what it is trying to convert? I am having problems determining which parameter is causing the error.
There's nothing that can quickly visualize it for you, but you can browse through the object and get at the internal list of parameters and view their names and values individually.
It will likely be faster just to write something that you can pass the command into and it will print out the name, DbType, Value.ToString() and Value.GetType().Name for each parameter.
void PrintCommand(DbCommand command)
{
Console.WriteLine("CommandType: {0}", command.CommandType);
Console.WriteLine("CommandText: {0}", command.CommandText);
foreach(var parameter in command.Parameters)
{
Console.WriteLine(" Parameter {0}, {1}: \"{2}\" ({3})",
parameter.ParameterName,
parameter.DbType,
parameter.Value,
parameter.Value.GetType().Name);
}
}
Try the immediate window:
? SQLCmd.Parameters["#MyParam"].Value