HiI'm new here and in this platform. I came across in some problems on linux client programming. I'm trying to stream data from a similar RPi platform to the thinger server but I am a bit confused about how and what I have to send.

I have a function that retrieves data from a serial port and this could be temperatures, relays on/off, led colors, etc. of another electronic board. If I receive a packet with register 0x01 and data filed is "00000001", for example, it means that the first relay is on. This relay is on if a door of an oven is open. So i want to show in thinger's dashboard "Door is open". My idea was:

Hi! First of all thanks for answering my question.Reading the documentation I figured out that I had to move the resource out of the loop, as you said. Now everything works excepts the update. In the data bucket, I set the refresh mode as "update by device", so every time something changes I should see it istantanley. The problem is that the bucket refresh values even after 1 second. I'll explain:I have this kind of RPi (called Gateway) that runs a software useful to intercept data between two electronic board (of an industrial oven). Now the primary board (where runs Android) is set to send data only if something happens, like switching a relay on or off. Now if I switch on a relay, the primay board sends the command to the secondary where there are all physical relays. The gateway intercepts this packet and sends a string to thinger ("Relay 1 on", for example). But it's not in real time. I post the code:

Ok, if I put the thing.handle(); out of the loop, the application runs correctly; i mean, data will sent every time something happens, not every second. But, if something changes too frequently (like every 20 ms) i get "Segmentation fault" error. It is strange because if I change the function call (data = serialRead()) with a static string (data = "HI"), thinger sends it without problems at "full speed", so on the device page i see a lot of MB of data incomimg.

Hi @Takenfal, your code seems to be ok, but your program is not working in real-time, as the thing.handle() method has a 1 second timeout that is waiting for server responses (and also avoiding running the loop constantly, which will turn your CPU to 100%). You need to call the thing.handle() inside the loop, or the server may disconnect you, or your device not react to server queries. If you want, you can decrease the timeout in this class:

// The MIT License (MIT)
//
// Copyright (c) 2017 THINK BIG LABS SL
// Author: alvarolb@gmail.com (Alvaro Luis Bustamante)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,

However, it could be even better to use threads for such things (to avoid high CPU usage). One thread reading from serial, and another one for handling thinger connection and streaming at an appropriate rate. However, this will take some more time and knowledge.

Eventually, I will be releasing an ASIO linux client to handle the client connections much much much efficiently. But it will require some dependencies like Boost Libraries.

Thanks a lot! Your information is precious! Sorry for bothering you but I have two other questions:

Even using the threads (one for reading from the serial and another for handle and streaming data) I get "segmentation fault" error every time I use serialRead() method instead of sending a single string variable lilke "Hello". If I run the program using serialRead() method, the program starts without problem and it waits unti data is sent from the two boards. But at the exact time when a data is sent, I get segmentation fault error.

It is possible to link the data bucket to an external database?

EDIT: Ok, the problem of the first point is because of the run.sh. I compiled the program with g++ and no more segmentation fault error occured.