How to send and save data to Thingspeak

Hi,

I am new in IoT using Arduino. I am using a Sparkfun LTE Shield (LTE Cat M1/NB-IoT Shield Hookup Guide - SparkFun Learn), an Arduino UNO, and an AT&T simcard to send data to Thingspeak. I could able to register operator and also send SMS to my cellphone using the shield library (its first and second examples). However, its third example is sending and saving data to hologram. Since my simcard is not a hologram one, I do not know how to edit the code such that I would be able to send data to Thingspek (I made the field for my data and I have its Write API Key/Channel feed).

Is there any code for this purpose?

I appreciate any help in advance.

Thank you,
Abbas

googling...

post to thingspeak sim900l

...may give you some ideas.

Hi,

Thank you for your suggestion. I have already searched a lot to find a code for this purpose based on my hardware settings, but I could not find one.

There may not be cut-and-paste-ready code for what you want to do, but your device can receive AT commands via a serial connection, and in the first half-dozen or so hits from that Google search I suggested, at least one shows how to post to Thingspeak using AT commands. All you need to do is connect the dots.

Hi DaveEvans,

Thank you for your reply. You are right. I found a code based on AT commands for another cellular module. However, I think I need to find the AT commands for Ublox SARA for the SparkFun shield.

Good deal. You can find the AT commands for your device in a document on the Sparkfun website.

Hi DaveEvans,

As you suggested I found some AT commands for this shield and they worked (Please look at the Arduino codes and LOG below). However, It seems "AT+UDNSRN" is not working correctly. I tested the command with the example that I found in the SARA-R4 series manual (https://www.u-blox.com/en/docs/UBX-17003787#[{"num"%3A2272%2C"gen"%3A0}%2C{"name"%3A"XYZ"}%2C59.527%2C572.677%2Cnull]). The IP address that I got for Google website (+UDNSRN: "142.251.40.132") is different from the one in the manual (+UDNSRN: "216.239.59.147"). Any idea to solve this issue?

Thank you!

Arduino code:

    lteSerial.println("AT");
    delay(1000);
 
    lteSerial.println("AT+CPIN?");
    delay(1000);
 
    lteSerial.println("AT+CREG?");
    delay(1000);

    lteSerial.println("AT+CGATT?");
    delay(1000);
    
    ShowSerialData();
    
    lteSerial.println("AT+CGDCONT=1,\"IP\",\""+apn+"\"");
    delay(1000);

    ShowSerialData();

    lteSerial.println("AT+CGACT=1,1");
    delay(2000);

    ShowSerialData();

    lteSerial.println("AT+USOCR=6");//TCP connection
    delay(3000);

    ShowSerialData();

    lteSerial.println("AT+UDNSRN=0,\"www.google.com\"");
    delay(6000);

LOG:

AT

OK
AT+CPIN?

+CPIN: READY

OK
AT+CREG?

+CREG: 0,1
AT+CGDCONT=1,"IP","SIM card_APN"

OK
AT+CGACT=1,1

OK

+PACSP1
AT+CGACT=1,1

OK
AT+USOCR=6

+USOCR: 0

OK
AT+UDNSRN=0,"www.google.com"

+UDNSRN: "142.251.40.132"

OK

Is that a problem? Both look like they are Google IPs. Otherwise, sorry...no idea. Maybe ask u-blox.

DaveEvans,

Thank you for your reply. Actually, I wanted to test this command before using it to find IP address of "api.thingspeak.com". I found two different IPs using this command : "3.224.210.136","3.213.58.187" (also, nslookup command on CMD Windows gives me these IPs). Moreover, I found that some websites report "184.106.153.149" as Thingspeak's IP. I used the "AT+USOCO" on Arduino code for these three IPs:

Example of the Arduino code:

lteSerial.println("AT+USOCO=0,\"184.106.153.149\",\"80\"");

But I got this error:

+CME ERROR: Operation not allowed

Any idea why I got this error? What is your suggestion regarding which IP address should I use for "api.thingspeak.com"?

I've had success posting to Thingspeak with 184.106.153.149 in the past (but they strongly recommend not using a static IP.)

Sorry, I don't know enough to help with the error question. I would have to google it, like you presumably have.

If you resolve it, please post the solution here, so others know how to do it.

DaveEvans,

I searched a lot and still searching to find out the solution. I will post it when I find it out.
Please share any ideas or suggestions with me in this regard.

Thank you

Did you look at the AT commands manual way down at the bottom of the Sparkfun website for your device that you linked in your first post? Its examples for the AT+USOCO command show a completely different format than the way you did it.

I have already looked at the manual for the AT commands, but since I am new to AT commands, I do not know which format should I use. Actually, if I use the format similar to the one mentioned in the manual, I get the error below. Any idea which format should I have for my Arduino code?

Arduino code:

lteSerial.println("AT+USOCO=0,"184.106.153.149",80");

Error:

too many decimal points in number

Sorry, don't know. I guess since your other commands worked, maybe you have it right, and the error is due to something else. Good luck!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.