Send multiple commands to sleeping Xbee module - xbee

I have an xbee module in cyclic sleep mode that sleep for about 5 sec, then wake up for 500ms and the go to sleep again and so on... I need to send multiple commands to this module in api mode but I have a problem... when it sleep only the last message is sent from coordinator. In detail I need to set a digital pin in high state for about 200 ms and then in low state again... the problem is when the commands are sent when the module is sleeping... when it wake up only the second command (digital pin to low state) is sent from coordinator, so nothing happens. Any solution? Is there any possibility to send more commands in api mode in a single frame?
Thank you in advance.

Which XBee module are you using? Some of the modules support timeouts on their digital I/O. You can configure the module to revert to its configured value after some elapsed time (in multiples of 100ms).
That would be a more reliable way to generate a 200ms pulse on one of the digital outputs.
I'm not sure which modules support this feature -- check in X-CTU or the documentation. The commands at ATT0 through ATT9 to set timeouts on D0-D9 and ATQ0 through ATQ4 to set timeouts on P0-P4.
It's possible this is only available in the XBee Wi-Fi I have been using, and not the sleeping radios you're using.

Related

RN4871 with Gattlib C library high latency

I am using RN4871 with the latest firmware to turn on multiple LEDs via an I2C LED driver. I use gattlib C/C++ library to communicate ("write without response") with the RN4871 through my Ubuntu (20.04) system and I measure the latency of communication via an oscilloscope connected both to my computer and the RN4871.
I set the communication parameters on the Bluetooth device to 7.5 ms intervals with zero latency.
The problem is if I send commands from my computer in 500ms intervals, my communication latency is below 20ms which is just perfect for my application. However if my commands are 1 seconds or longer apart the latency rises up to 250ms! In my application I need extremely fast communications with minimal latency (below 40ms) and of course my commands are sent at variable intervals (can be even 10 seconds apart). I dont know where this issue comes from? Does it have to do with some sleeping process within the RN4871 that occurs when there is no data to transfer for more than 500ms or something else?
Thanks!

AWS IoT Jobs and OTA Updates when device is in sleep mode

What happens if I send an OTA Update and the device is in deep sleep mode? It wakes up immediately, waits for the next wake up and then runs automatically or it does not run at all on it?
Depends a lot on what your device is, how "deep sleep" and wakeup from it is implemented in this device and how it's connected to Internet.
Option 1: no. Most likely the networking hardware is switched off to save power and (if it's really deep sleep) the micro's core is also suspended (i.e. it doesn't execute code). In this state the device couldn't receive any messages from the network.
Option 2: depends on what the device does when it wakes up. If it connects to Internet and connects to AWS IoT and receives the command, then probably yes. This functionality is up to the developer of embedded firmware to design and implement. Otherwise no.

Delay measurement and synchronisation between raspberry pi

I am doing a project with 2 raspberry pi which work as servers and a laptop which is the client.
I have attached to each raspberry and usb microphone and using the Portaudio Library im capturing audio streaming
and send it back to the laptop through a tcp/ip connection.
The scope of this project is to locate sound sources and it works like this. I run a .c file on each raspberry which are
connected on the same LAN as with the PC laptop. When this program is running on both raspberryies i have a message
"Waiting connection for a client". The next thing to do is just to run the matlab file which will start the both raspberries
and record. I have managed to synchronize the raspberries to start in the same time through a simple condition like
do
{
sleep(0.01);
j = read(newsockfd, &start,1 );
} while (j==0);
so right before both raspberries have to start recording i pause them in order to finish the initialization commands and so on
and then i just send a character "start = 'k'" through my matlab program
t1,t2 are tcp connections
start = 'k';
fwrite (t1, k);
fwrite (t2, k);
from this point both raspberries open the PortAudio stream and call recordCallBack function.
When I run the application and clap, i still get a delay of 0.2s between them which causes
an error of 60 meters. I have also checked the execution time of the fwrite function but that might
save me about 0.05 seconds which will still lead to results far from reality.
This project is based on TDOA measurement and it is desired to have a delay under 0.01 seconds to get accuracy <1m.
I have heard that linux has some very accurate timers, and i was thinking that maybe i could use that to
clock the time inside the functions in the .c file. Anyway if you have any ideas of how i can measure the delay from
the point i send the character 'k' from matlab until the point where the audio stream is opened in microphone, or any
way how i could synchronize the 2 linux servers please help.
ps: both are raspberry 2 pi and connected through UTP cables so the processing and transmission rates should be the same
It looks like an interesting project but I think you underestimate the problem a little bit. The first issue is that you need to synchonize the two sensors. Given the speed of sound and if you want an accuracy of about 1m you need to synchronize them with about 1ms accuracy. You could try with the Network Time Protocol but I'm not sure you can reach this accuracy even with a master on the local network. Better synchronization can be achieved with PTP (over ethernet) or GPS if you can receive a GPS signal.
Then if you manage to achieve this, a first step could be to record a few hand claps on both raspberry pi, save the timestamp when you start recording on both and see if you actually obtain something significant. Maybe you will also need to use a microcontroller and a real-time operating system instead!
There are many ways to synchronise clocks. It could be in a system level or in application level.
System level tend to be easier because there are already tools to do the job. I don't recommend you doing PTP at this stage, as mentioned by Emilien, since it is quite complicated to make it work. Instead I would recommend you to use normal setup via the same NTP network on all machines.
Example of NTP setup:
Query the server with # ntpdate -q 0.rhel.pool.ntp.org
If it is running, setup your local clock with # ntpdate 0.rhel.pool.ntp.org 1.rhel.pool.ntp.org
OBS: # means root user (which most likely means that you will need to run the command with sudo), whilst $ means normal user.
Check all machines times with $ date +%k:%M:%S.%N which will return the clock down to a nanosecond resolution.
If that doesn't acheive the desired result then try the PTP aproach, or just synchronise all your devices when they connect to the master, where your master can normalise each independant clock. I will not go into details here.
Then you can send your audio data via TCP/IP (or perhaps UDP/IP to lower latency) like you mentioned before, but always send the timestamp of your slave machine associated to a audio frame using clock_gettime() function with CLOCK_REALTIME as the clk_id argument.

Disable regular advertising programmatically on CC2541 IC and advertise only by demand, is this possible?

I just want to find out if CC2541 BLE device can be in sleep mode and wake up only when it is scanned by an observer device. Meaning it does not advertise data during sleep mode, but only respond when scanned using specific UUIDs. Is this possible? Is it also possible to wake it up for regular advertising and turn it back to sleep mode again using UUIDs while scanning? Thanks in advance.
CC2541 BLE device can be in sleep mode and wake up,and can wake it up for regular advertising and turn it back to sleep mode again.But not by "it is scanned by an observer device".
When in sleep mode,it can't [be] scan[ned].So you can only use a sleep timer or interrupt to wake it up.
Thank you.
Best Regards,
Viki Shi
TEXAS INSTRUMENTS
You can only read the device name and device address for CC2541 without pairing, since it only advertises with those information. All other information has to be accessed over GATT, such as the accelerometer data, battery data and data from the other sensors.

Does USB mass-storage class requires re-enumeration after timeout?

this might be a stupid question,
I was debugging a USB storage device on an ARM-CortexM4 platform (STM32F4 series) which runs embedded Linux. The ARM is working as USB host, and tries to communicate with a thumb drive in USB full speed (12Mb/s).
Now here is the problem. After successful enumeration and several SCSI commands thru BULK transfers, the capacity and everything can be read correctly. However, after about 15 seconds when I try to send these SCSI commands again (under same condition), the USB host controller just returns 'Transaction Error', which looks like the device is not responding to BULK transfers anymore (not ACKing) and the host controller times out. The question is, is there any timeout mechanism for USB mass-storage class or SCSI system such that, after a timeout the system must be re-enumerated or re-probed, otherwise it won't respond anymore?
I understand this might be due to a stupid error in my program, or due to some limitations on the specific hardware. However when I used usbmon module in Linux on a PC to capture the transfers on the very same thumb drive, I can see the operating system actually sends a sequence probing command (Read-max-Lun followed by Test-unit-ready) every 5 sec, which could be the reason why the thumb drive doesn't fail on my PC.
Thanks! I'm looking forward to any replies.
I think you're on the right track with the Test Unit Ready commands.. I am in the middle of writing a mass storage device driver for an embedded device and When testing on OS X, after the initial SCSI queries, my device receives Test Unit Ready command about once every second when no other activity is occurring. Since your post is quite old, I recommend you post your own solution if you've since solved your problem.
Otherwise try adding periodic test unit ready commands from the host side when there is no other activity.. You could set and activate a timer whenever USB activity is occurring. If the timer fires, u can send a Test unit ready command.. Rinse repeat.

Resources