Parse Quick Start with YUN - parse-platform

i'm tring to start with YUN and Parse with first example:
ParseObjectCreate create;
create.setClassName("TestObject");
create.add("foo", "bar");
ParseResponse response = create.send();
Serial.println("\nResponse for saving a TestObject:");
Serial.print(response.getJSONBody());
if (!response.getErrorCode()) {
String objectId = response.getString("objectId");
Serial.print("Test object id:");
Serial.println(objectId);
} else {
Serial.println("Failed to save the object");
}
response.close(); // Do not forget to free the resource
When i lauch RUN i obtain only:
Test object id:
without any other else.
What could be the problem?
Thanks
NR

My experience was that I needed to run the "setup" Arduino sketch (just once) to get the Linux side properly configured. After that I could run the sample scripts repeatedly with success.

Related

Autohotkey concerning Websocket | Winhttp and stuff question

Trying to get trading information via websocket method. There are many guides and manuals for other languages, I would like to get it via Autohotkey preferably.
Below is the code that I am using when receiving info with Autohotkey.
Get_Price(Target_Site, Target_Coin, Price_Type = "KRW") {
if (Target_Site = "UpBit") {
API_Url := "https://crix-api-endpoint.upbit.com/v1/crix/candles/minutes/10?code=CRIX.UPBIT."
}
Result_URL := API_Url "" Price_Type "-" Target_Coin
Result_Json := Get_WinHttp(Result_URL)
RegExMatch(Result_Json, "tradePrice"`":(.*?)\.", Result) ;If(Target_Coin="BTT") Or (Target_Coin="DOGE") If(Target_Coin="BTT") Or (Target_Coin="DOGE")RegExMatch(Result_Json, "tradePrice"`":(.*?)\,", Result)
Return Result1
}
It seems like the approach above was kinda more explicit and easy compared to Websocket. Only thing I had to was forming right url with my info and sending that url and get the result from the website.
But, when it comes to websocket, I know of the right url, right info to send, but don't know how I can send and .. yeah how.
Url : wss://api.upbit.com/websocket/v1
What to send : '[{"ticket":"test1243563456"},{"type":"trade",{"type":"trade","codes":["KRW-BTC", "KRW-ETH"]}]'
How : I don't know. But I happen to come across some interesting AHK example, I am wishing I can modifying this. Will appreciate if you can have a look and guide me if possible.
#Include, Websocket.Ahk
class Example extends WebSocket
{
OnOpen(Event)
{
InputBox, Data, WebSocket, Enter some text to send through the websocket.
If (ErrorLevel==1)
this.Close()
this.Send(Data)
}
OnMessage(Event)
{
MsgBox, % "Received Data: " Event.data
new Example("wss://echo.websocket.org/")
}
OnClose(Event)
{
MsgBox, Websocket Closed
this.Disconnect()
}
First things first, in AHK v1 you escape quotes by doing a double quote "".
Here "tradePrice"`":(.*?)\." your resulting string has a double quote in it by pretty much sheer luck.
Actually it's supposed to be done like this: "tradePrice"":(.*?)\.".
You'll need to correctly escape quotes in what you're going to do next.
Also, since you have a json response, you might want to parse the json and use it how it's supposed to be used.(See AHK JSON/Jxon)
So about the websocket.
Personally I'd say G33kDude's example(Github) explains it pretty well, but maybe you were thrown off by the object oriented code style choice he's made for it.
It's not that easy to understand if you're not experienced with OOP/OOP AHK I guess.
Here's an example for calling an echo websocket with the data you wanted to send.
#Include WebSocket.ahk
New HelperClass("wss://echo.websocket.org/")
class HelperClass extends WebSocket
{
OnOpen(Event)
{
DataToSend := "[{""ticket"":""test1243563456""},{""type"":""trade"",{""type"":""trade"",""codes"":[""KRW-BTC"", ""KRW-ETH""]}]"
this.Send(DataToSend)
}
OnMessage(event)
{
MsgBox, % "Received a message!:`n" Event.data
this.Close()
}
OnClose(Event)
{
MsgBox, Websocket Closed
this.Disconnect()
}
OnError(Event)
{
MsgBox, Websocket Error
}
__Delete()
{
MsgBox, Exiting
ExitApp
}
}
You have to make this class that extends the WebSocket class due to how it's designed, but it's actually pretty convenient if you know OOP (AHK).
So here's how it works:
New HelperClass("wss://echo.websocket.org/")
You prepare the behind the scenes magic open a websocket connection to the specified websocket
The OnOpen() function runs in your HelperClass once the magic has been prepared
this.Send(DataToSend)
You call the Send function (which if found inside the WebSocket class) and pass in the data you want
You receive a response message (OnMessage() runs in your HelperClass), or maybe you receive an error (OnError() runs in your HelperClass)
The connection closes, so OnClose() runs in your HelperClass.
And you also want to reset the behind the scenes magic by calling Disconnect() function inside the WebSocket class by doing this.Disconnect()
(When I say inside HelperClass or inside WebSocket class, it's actually incorrect because they're kind of the same class, you're just extending WebSocket class with your HelperClass)
So that's about it.
Misc notes:
Download the WebSocket class from G33kDude's GitHub and include the WebSocket.ahk file to your own script with #Include(docs).
G33kDude example script uses #Include ../WebSocket.ahk to include it, because his example script is in a subfolder, so he goes back one folder with .. and then specifies the file to include.
Also note how the quotation marks are correctly escaped in the DataToSend variable.

Kafka state store not available in distributed environment

I have a business application with the following versions
spring boot(2.2.0.RELEASE) spring-Kafka(2.3.1-RELEASE)
spring-cloud-stream-binder-kafka(2.2.1-RELEASE)
spring-cloud-stream-binder-kafka-core(3.0.3-RELEASE)
spring-cloud-stream-binder-kafka-streams(3.0.3-RELEASE)
We have around 20 batches.Each batch using 6-7 topics to handle the business.Each service has its own state store to maintain the status of the batch whether its running/Idle.
Using the below code to query th store
#Autowired
private InteractiveQueryService interactiveQueryService;
public ReadOnlyKeyValueStore<String, String> fetchKeyValueStoreBy(String storeName) {
while (true) {
try {
log.info("Waiting for state store");
return new ReadOnlyKeyValueStoreWrapper<>(interactiveQueryService.getQueryableStore(storeName,
QueryableStoreTypes.<String, String> keyValueStore()));
} catch (final IllegalStateException e) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
When deploying the application in one instance(Linux machine) every thing is working fine.While deploying the application in 2 instance we find the folowing observations
state store is available in one instance and other dosen't have.
When the request is being processed by the instance which has the state store every thing is fine.
If the request falls to the instance which does not have state store the application is waiting in the while loop indefinitley(above code snippet).
While the instance without store waiting indefinitely and if we kill the other instance the above code returns the store and it was processing perfectly.
No clue what we are missing.
When you have multiple Kafka Streams processors running with interactive queries, the code that you showed above will not work the way you expect. It only returns results, if the keys that you are querying are on the same server. In order to fix this, you need to add the property - spring.cloud.stream.kafka.streams.binder.configuration.application.server: <server>:<port> on each instance. Make sure to change the server and port to the correct ones on each server. Then you have to write code similar to the following:
org.apache.kafka.streams.state.HostInfo hostInfo = interactiveQueryService.getHostInfo("store-name",
key, keySerializer);
if (interactiveQueryService.getCurrentHostInfo().equals(hostInfo)) {
//query from the store that is locally available
}
else {
//query from the remote host
}
Please see the reference docs for more information.
Here is a sample code that demonstrates that.

qml qt grabToImage get image bytes

For some reason, saving a png back out from qml directly doesn't work. I have a qml UI on top of a Golang application. When I do
source.grabToImage(function(result){
console.log("image: ", result.url)
if (!result.saveToFile(urlNoProtocol)){
console.error('Unknown error saving to',urlNoProtocol);
} else {
console.log("saved to " + urlNoProtocol)
}
I get an error saving out. The location to save the file is coming from a fileDialog and I preprocess it to remove the file:// which I understand needs to be removed before using saveToFile. However I get an unknown error saving from the above code.
I suspect this is something to do with the qml being embedded in the binary application (perhaps to do with qrc:// or something)
Anyway my current plan is to send the image to the golang backend and save it out from there, so my question is, how from grabToImage or saveToFile can I get the image bytes that I will then save?
N.B Using therecipe/qt for the interface between Golang and qml
I have used this method for grabbing screen shots..
function performScreenShot(item, name) {
if(typeof(item) === "undefined") {
return;
}
else if(typeof(name) !== "string") {
name = "screenshot.png"
}
item.grabToImage(function(result) {
result.saveToFile(name);
});
}
Usage example:-
performScreenShot(main, "screenshot-" + screenShotIndex + ".png")
Where main is my object id and screenShotIndex is something im incrementing so as not to override any previous capture.
Ensure that you have write permission on the device.

How can I manipulate the REST API GET generated by YANG in Opendaylight?

PUT, DELETE, POST can be operated as shown below.
By the way, I do not know how to do GET.
Please help me.
// PUT & DELETE (mapped to WRITE, DELETE of MD-SAL)
public void onDataTreeChanged(Collection<DataTreeModification<GreetingRegistry>> changes) {
for(DataTreeModification<GreetingRegistry> change: changes) {
DataObjectModification<GreetingRegistry> rootNode = change.getRootNode();
if(rootNode.getModificationType() == WRITE) {
...
}
else if(rootNode.getModificationType() == DELETE) {
...
}
}
// POST (mapped to RPC of MD-SAL)
public Future<RpcResult<HelloWorldOutput>> helloWorld(HelloWorldInput input)
{
HelloWorldOutputBuilder helloBuilder = new HelloWorldOutputBuilder();
helloBuilder.setGreeting("Hello " + input.getName());
return RpcResultBuilder.success(helloBuilder.build()).buildFuture();
}
// GET (???)
How should I implement it?
You don't actually have to implement anything for GET in your code, when you want to read from YANG modeled MD-SAL data, the GET method is be available by default, and returns whatever data you ask for in the URL. It is important to point to the correct URL.
If you want to do some processing on data before returning it to the user, you can use RPCs with POST, and do the processing in the RPC based methods. In your example above, you could pot the search keys into HelloWorldInput, do the processing in helloWorld(), and return results in HelloWorldOutput.

GoogleUser.getAuthResponse() doesn't contain access_token

UPDATE2: I revisited this issue and have solved the problem by carefully following the doco linked below. But first, for those who are struggling with this, you are in good company. There are so many versions of the doco from Google it is confusing! Do you include platform.js or client.js in your html? Do you load gapi.auth or gapi.auth2? Do you use gapi.auth2.render or gapi.auth.authorize, or gapi.auth2.init, and so on.
The way that returns an access_token (as of this article date) is linked below. I managed to get this working by carefully following the guide and reference using platform.js. Other libraries are then dynamically loaded such as client.js using gapi.load('drive', callback).
https://developers.google.com/identity/sign-in/web/listeners
https://developers.google.com/identity/sign-in/web/reference
==== ORIGINAL ISSUE FOR PROSPERITY ====
UPDATE 1:
I've updated the code sample to do a recursive search of the googleUser object. At least this shouldn't break in a subsequent library.
Below is a code snippet to handle an issue where the access_token in the Google gapi.auth2.AuthResponse object is not at the top level... it is hidden :( in the depths of the object!
So it is retrievable, but not at the top level!!?? I've noticed it seems to be a timing issue... once the application is running for a while on subsequent checks, it does contain the access token at the top level!!
var authResponse = _.googleUser.getAuthResponse();
_.id_token = authResponse.id_token; // Always exists
// access_token should also be a param of authResponse
if (authResponse.access_token) {
debug("Worked this time?");
_.access_token = authResponse.access_token;
} else {
// !!! Internal object access !!!
debug("Attempt to get access token from base object.");
_.access_token = _.objRecursiveSearch("access_token", _.googleUser);
if (_.access_token) {
debug("Access token wasn't on authResponse but was on the base object, WTF?");
} else {
debug("Unable to retrieve access token.");
return false;
}
}
_.objRecursiveSearch = function(_for, _in) {
var r;
for (var p in _in) {
if (p === _for) {
return _in[p];
}
if (typeof _in[p] === 'object') {
if ((r = _.objRecursiveSearch(_for, _in[p])) !== null) {
return r;
}
}
}
return null;
}
I'm guessing getAuthResponse somehow provides a callback once it is ready, but I can't see where in the API.
https://developers.google.com/identity/sign-in/web/reference
I know this question is fairly old, but it appears first when googling for ".getAuthResponse() doesn't have access_token," which is how I got here.
So for those of you in 2016 (and maybe later) here's what I have found out
There's a secret argument on .getAuthResponse, not documented anywhere I have found. If you would run the following in your app
console.log(gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse);
You would see that you get the following (copy/pasted from my console)
function (a){if(a)return this.hg;a=.HE;var c=.rf(this.hg);!a.Ph||a.dL||a.Lg||(delete c.access_token,delete c.scope);return c}
This shows that the .getAuthResponse() function looks for an argument, and as far as I can tell doesn't even check its value -- it simply checks if it is there and then returns the whole object. Without that function, the rest of the code runs and we can see very clearly it is deleting two keys: access_token and scope.
Now, if we call this function with and without the argument, we can check the difference in the output. (note: I used JSON.stringify because trying to copy/paste the object from my browser console was causing me some issues).
console.log(JSON.stringify(gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse()));
console.log(JSON.stringify(gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse(true)));
getAuthResponse() object
{
"token_type":"Bearer",
"login_hint":"<Huge mess of letters>",
"expires_in":2112,
"id_token":"<insert your ridiculously long string here>",...}
getAuthResponse(true) object
{
"token_type":"Bearer",
"access_token":"<an actual access token goes here>",
"scope":"<whatever scopes you have authorized>",
"login_hint":"<another mess of letters>",
"expires_in":2112,
"id_token":"<Insert your ridiculously long string here>",
...}
Figured out the fix for this. Turns out that if we don't provide the login scope config in gapi.auth2.init it doesn't return access_token in getAuthResponse. Please call gapi.auth2.init as given below and access_token will be present.
gapi.auth2.init({
client_id: <googleClientID>,
'scope': 'https://www.googleapis.com/auth/plus.login'
})

Resources