I know how to save data like(1,2,2.3,65.2).
I was wondering if its possible to save and retrieve data like('AP09BN7886')(String) in thingspeak.com?
I am sending data to thingspeak.com via esp8266 connected to my arduino UNO using AT commands.
Can I also retrieve data from thingspeak.com using esp8266 in Arduino UNO?
The arduino examples from thingspeak.com on GitHub shows an example to handle string data via ethernet. This could be a perfect starting point for you.
//...
// Create HTTP POST Data
tsData = "api_key="+thingtweetAPIKey+"&status="+tsData;
client.print("POST /apps/thingtweet/1/statuses/update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(tsData.length());
client.print("\n\n");
client.print(tsData);
//...
Related
I don't know how can I write a smart contract in Solana that after executing the logic, returns an array of integers, strings, ... to the client, and how can I fetch it using Web3?
There's a syscall available to on-chain programs called set_return_data, which puts data into a buffer that can be read by the higher-level programs using get_return_data. This all mediated through opaque byte buffers, so you'll need to know how to decode the response.
If you want to fetch the data from the client side, you can simulate the transaction and read the data back from the return_data field in the response: https://edge.docs.solana.com/developing/clients/jsonrpc-api#results-50
The RPC support in simulated transactions is very new in version 1.11, but the return data is available in earlier versions.
Source code for set_return_data at https://github.com/solana-labs/solana/blob/658752cda710cb358d7ccbbc2cee06bf8009c2d4/sdk/program/src/program.rs#L102
Source code for get_return_data at https://github.com/solana-labs/solana/blob/658752cda710cb358d7ccbbc2cee06bf8009c2d4/sdk/program/src/program.rs#L117
So, programs do not return data (other than success or failure).
However; most programs write data to a program owned account's data field and this could be read from client apps (Rust, Python, TS/JS, etc.).
If using the Solana web3 library, you can call getAccountInfo on the Connection object. This will return the byte array of the account. You will then need to deserialize that data. You have to know how the program serializes the data to reverse it successfully.
Check the Solana Cookbook for overview using borsh https://solanacookbook.com/guides/serialization.html#how-to-deserialize-account-data-on-the-client
const { value, done } = await reader.read();
There is this above line used in the docs (https://web.dev/serial/) to read the data coming from the serial port. Docs say that the done will turn out to be true when all of the data sent by the serial device is read. But it's not getting true and since it is in the while loop, my code is getting stuck on this line, waiting further for the serial device to send new data even though all of the data has been sent by the serial device.
(I am using Chrome browser, Windows and the code is written in js file)
I found a workaround. What I did was whenever the ReceivedData was updated with '\u0004\u0003' string, it meant that the serial device has completed the transfer of data since '\u0004\u0003' means EOTETX (End of transmission, end of text). Atleast in my case it worked since I knew the way in which the serial device wraps it's actual message within STX and EOTETX.
Refer the code below to have a proper idea of what I'm talking about. I wrote it in this way:
while (port && port.readable){
const { value, done } = await reader.read();
if (done) {
break;
}
// value is a string.
ReceivedData +=value;
if(ReceivedData.includes('\u0004\u0003')){
break;
}
}
I read that same info in the docs and was also confused. I have only observed done=true after calling reader.cancel(). Perhaps the docs should be clarified.
It is needed after cancel to break out of the while loop.
You can see it in my source code for https://webserial.io :
https://github.com/williamkapke/webserial/blob/8ae91a2fd978eede59182c2a4b28725c12c932a8/src/stores/connection.js#L107
I am trying to implement an inter-process communication.
The model: Part A -> Sends messages to Part B.
I have implemented this using Client-Server example from ZMQ tutorial (code attached bellow), but facing issues that the process is "locked".
What is the best practice to implement this kind of model?
It is not classic "Client-Server". Actually just one part sends data to the second part, and second part uses it.
Is there an option to send a message with a timeout, that it will not lock the process?
Any input / example will be very appreciated!
Server:
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REP);
socket.bind("tcp://*:5555");
..
socket.recv(&request); // SERVER.receives first
socket.send(reply); // SERVER.sends next to Client
.. // .analyze .recv'd data
Client:
requester = context.socket(ZMQ.REQ);
requester.connect("tcp://localhost:5555");
requester.send(str.getBytes(), 0); // CLIENT.sends
byte[] reply = requester.recv(0); // CLIENT.receives
Using shelf_auth I can extract current user information from request this way:
getAuthenticatedContext(request)
.map((ac) => ac.principal.name)
.getOrElse(() => 'guest')
but, obviously, I need a request for that to work :)
On the other hand, using shelf_web_socket, establishing of websocket connection executes handler like that:
handleWS(CompatibleWebSocket ws){
// Here I should get user from getAuthenticatedContext()
// but I cannot due to absence of Request here.
ws.messages.listen(...);
};
rootRouter.get('/ws', webSocketHandler(handleWS), middleWare: authMiddleware);
But I have no idea how to forward original socket connection request to my handleWS, to be able to know which user just connected to server.
Another question is what is best practice to store these open sockets, to being able to send broadcast messages to all connected clients, and delete corresponding socket when it's closed.
First what is coming to my mind is to store sockets in a map like Map<int,CompatibleWebSocket>, where int is CompatibleWebSocket.hash().
Then I can iterate over Map.values() to do broadcast, and delete by key when connection is closed.
I can't get if that technique overcomplicated for such task and maybe exist more convenient way doing that, like storing them in a list? Or can I join Streams somehow for broadcasting?
I'm creating a web app that will function as an endpoint for an experiment that will use a RockBlock unit. The data that comes from the unit is routed through the Iridium satellite network and then send to the endpoint via a http POST. We're returning, 'OK'(Status Code:200), immediately after receiving data.
I'd like to:
Store the data,
Visualize one parameter of these data in a x-y plot in real-time,
Display other data parameters numerically in a dashboard type layout.
Can firebase help me quickly stand up this sort of application? Are there some examples of an implementation like this available for me to look at in firebase "knowledge base"?
Thanks ahead for your assistance,
P.S. Here is some sample PHP code that I'm starting with that shows one way to get the data, decode the payload data (in hex), and send a response.
$imei = $_POST["imei"];
$momsn = $_POST["momsn"];
$transmit_time = $_POST["transmit_time"];
$iridium_latitude = $_POST["iridium_latitude"];
$iridium_longitude = $_POST["iridium_longitude"];
$iridium_cep = $_POST["iridium_cep"];
$data = $_POST["data"];
$decoded = pack('H*', $data);
echo "OK";
You can use Firebase to store your information and some JS framework to display it. If you want to use Firebase REST services, you are warned that you will need to implement a server somewhere that using your Firebase secret, will generate a token that your device can use to POST on Firebase. Alternatively you can feed your device with your Firebase secret if you trust the device.