Last known value from Adafruit IO on Arduino - arduino

I'm working on a basic sketch for an Adafruit Huzzah which uses the Adafruit IO MQTT library. This is put together by copy/pasting from various sources and examples, and mostly works - but there's one thing I can't figure out.
Right now, I'm using a line of code which fires off a handler every time a new message is received via the feed I'm subscribed to:
group->onMessage("daniel", handleMessage);
This is fine, and does what I need it to do for values which are updated.
What I want to do, however, is grab the last known value on the feed during the setup() routine, rather than having to wait for a new value to come though.
In MQTT parlance, I believe this is known as retained messages, which I think Adafruit IO has on by default, but I don't know how to grab these values during the startup() process.
Can anyone help me out?
(If you're interested, here's my code so far: https://github.com/LimeBlast/family-box/blob/master/family-box.ino)

Short answer is you don't... do anything.
Retained messages are delivered just the same as normal messages (via the onMessage callback), they are just delivered as soon as you subscribe to the topic.

I also had this problem. Here is the full explination
The get() function wil ask the Adafruit servers to resend the last value of the feed to this client only. When the value is received, the handler will be executed.
exampleFeed->get();

Seeing as I've just found the answer to the question I was asking, I figured it only right I post it here.
The command I was looking for, after having setup the feed, was ->get(), as shown in this example.

Related

SIM5216A phone functionality (CFUN) is not maintained

I'm quite new to working with Arduino/GSM and have had problems getting basic HTTP functionality working. I am currently facing multiple problems - one being that the 3G shield I am working with (SIMCOM SIM5216A) does not seem to want to connect to a carrier! :(
However, the problem I would like to focus on for this question is that Phone Functionality - designated through the AT+CFUN command - does not seem to be maintained through power cycles. Additionally, sometimes after modifying the CFUN, the modem will run a soft reset.
Here is the command I have been using to modify the phone functionality of the modem:
AT+CFUN=1,0
I am under the impression that the second parameter should stop it from running a soft reset.
I have attempted to save the AT configuration by following advice in this question's accepted answer - here is the output from power on:
START
+STIN: 25
+STIN: 25
+CPIN: READY
SMS DONE
PB DONE
AT+CFUN=1,0
OK
AT&W
OK
However, whenever I next reset, I will get the following:
AT+CFUN?
+CFUN: 4
OK
So, my question is how can I save the CFUN configuration to be consistent between power cycles? (If you happen to be able to offer advice on why I can see medium-strength signal but cannot connect to an operator network, any advice would be welcome there too, however that is not the focus of this question)
With thanks,
BadDevH.
Exactly what that is saved with AT&W is a rather muddled, see this answer for details. However, regardless of that, the AT+CFUN command is controlling such a dynamic behaviour that I cannot imagine any manufacturer ever that has saved this with &W. Think more of CFUN more like setting a fixed cruise control speed while driving a car. There is no way the car will continue with the speed from last time when started.
For normal phones the default behaviour is value 1 - full functionality - because that is the very core functionality of what they do1, but for a GSM module shield, I am guessing that the default behaviour is set to no radio in order to save power, so it stays off until you need it at which point you need to explicitly turn it on.
1
And even in the case of no sim card present, it shall still be able to make emergency calls.

How to know if you missed an incoming call in AT commands

I am using Putty to simulate my phone's modem connected via serial. When my phone receives a call it outputs 'RING' into putty but when the caller cancel the call Putty doesn't out put any response or result.
How would the modem know that the caller disconnect/cancelled the call, but not output it in putty?
Thanks
To detect missed calls you can try three things.
Check if there is a suitable AT+CIND indicator you can turn on. I do not think call will do since I assume it only goes to 1 when the call is answered. If your phone supports callsetup or something similar that should be what you need (you will have to implement logic to detect when a call does not go to state active).
For an example of enabling AT+CIND indicators, see chapter "8.57 Informative examples" in 27.007 for more explanation, and pay close attention to The subparameter order in the command is defined by the query command order, e.g.
if AT+CIND=? returns
+CIND: ("abc",(0-1)),("xyz",(0,1)),("call",(0,1))
then call is index 3, and for
+CIND: ("abc",(0-1)),("call",(0,1)),("xyz",(0,1))
call is index 2. Do not hard code any assumptions here, this should be parsed and checked run-time (one check at the beginning is enough).
Alternatively you can upon RING start polling call status with AT+CLCC until the call is no longer listed.
Or you could poll the MC phonebook storage and detect changes.
Most modems show the incoming phone number and a RING when a call is received and an END when the call is cancelled. To view the missed calls, you may use the following AT Commands.
AT+CPBS="MC"
AT+CPBR=1,99
First command tells the modem to look in the missed call phone book and the second command loads entries from 1 to 99. Note that this behavior is not standard. I was able to replicate this on a GSM module but not on my 3G modem. Try it on your modem and check if this works. All the best.

Arduino WiFi shield stop working at WiFi.status()

UPDATE:
I pinpointed where the problem is coming from. To avoid any complication, I'm using ScanNetwork example, so I don't even have to put in SSID. The code stops functioning on the board as soon as it hits WiFi.status().
I have a Serial.println before and after it tries to get a WiFi.status(), the serial.println after wasn't performed, and of course, I'm still not connected.
I've downloaded fresh copy of the code, and the situation remains the same. I've really run out of idea....
I'm using the official arduino wifi shield, and I have the following code:
status = WiFi.begin([ssid],[pass]);
Serial.println(status);
Status is neither WL_CONNECTED nor WL_IDLE_STATUS, which are the two possible responses outlined in the official reference http://arduino.cc/en/Reference/WiFiBegin
Status is the number 4.
and of course, I couldn't connect to wifi.
What is this????
I've pressed the reset button a million times, is there a more powerful factory restore button?
I've figured it out.
Apparently, there's a jumper, that when you put it in, it'll kick the shield into a DFU-mode that enables reprogramming. And the shield wouldn't be present as a result.
According to WiFi.h The return values of the begin() functions (all three of them, one for each security scheme) are ints. It is not stated outright on this function but I believe that just as with the status() function the return type is a wl_status_t. wl_status_t is an enum declared in wl_definitions.h As:
typedef enum {
WL_NO_SHIELD = 255,
        WL_IDLE_STATUS = 0,
        WL_NO_SSID_AVAIL,
        WL_SCAN_COMPLETED,
        WL_CONNECTED,
        WL_CONNECT_FAILED,
        WL_CONNECTION_LOST,
        WL_DISCONNECTED
} wl_status_t;
So your 4 is WL_CONNECT_FAILED. Probably not surprising to you since, you know, you connection failed.
The hobbiest's debugger, AKA reset button, will only do so much. Printing the status was a good start. Be sure you are using the right flavor of begin() for you security type, you seem to be using the one for WPA. Consider shutting off you router's security completely (if safe to do so in your area), or using a spare router, to test the ability of the shield to communicate at all. Also this may sound obvious but check for a misspelling of the SSID.

AT command for disable Radio Signal Strength Indication and alike?

Im working on a program to send and recieve SMS using a GSM modem and my computer.
I have gotten sending and receiving to work - well sort of.
Once in a while my program is sent into a total chrash due to modem is mixing up information about Radio Signal Strength Indication and alike, while also serving my program with the hex code for the message.
My code can handle the hex code just fine. but I have seen the following line popup while im decoding a byte stream:
^RSSI: 2
So far I've seen it send out values between 1 and 10.
Is there an AT Command that can disable them? I have no need for them.
Or alternative: Is there a general syntax for them, so I can filter them out before decoding?
Im leaning towards a filter solution. But that would be more easy to implement if I knew whenever modem is sending out on the form: "^SOMETHING: xxx", then It would be nice to know if it is always followed up be a delimiter say for instance "\r".
You should try turning off periodic messages as using AT^CURC=0.
Information regarding the AT^CURC command:
AT^CURC? Current setting of periodic status messages
AT^CURC=? See what you possible values are
AT^CURC=0 turn off periodic status messages
The best way to tackle this scenario would be to replace that part of the response with an empty string because otherwise, it will be difficult to check even if the command sent to disable it is working or not.
This regex will match all those. You can replace them ideally by an empty string.
(\\n|\\r|\\r\\n)\\^.*(\\n|\\r|\\r\\n)

IMediaControl::Run followed by IMediaControl::Stop followed by IMeidaControl::Run doesn't switch on certain Onboard cameras

I have a DirectShow webcam application. I make use of Sample Grabber to get the buffer callbacks and IVideoWindow to control the display co-ordinates for the Preview. I have Preview and Capture Streams which I run as below.
g_pBuild->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video,cam,g_pGrabberF,pNullRenderer2); g_pBuild->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video,cam,NULL,NULL);
On certain On board cameras, IMediaControl::Run followed by IMediaControl::Stop followed by IMediaCOntrol::Run doesn't switch on the camera.
Extenal USB cameras work properly here. How can I diagnose more on this? Any pointers, please help.
Maybe its specific to a certain hardware issue in the unit.
Do a quick test by adding sleep of 1 sec between calls.
If it does help than you need to find a way to know when to unit state in idle or not.
There are two important parts of the question which you did not provide:
Filter graph topologies
HRESULTs of the method calls
A problem you might be having is that one of the filters in the topology does not handle well state transitions and fails somewhere between states. Supposedly your second Run meets it still trying to complete Stop. You might get a HRESULT there which indicates the issue (better for you) or the filter fails silently.
The filter graph's is the unlikely source of the bug itself. Chances are high that it does everything flawlessly, however since internally it distributes the calls between filters, one of the filter is letting you down.

Resources