🎁📬❄️📦Adafruit Holiday Shipping Deadlines 2019: Please place all UPS 2 Day orders by 11am Monday, December 16 📦❄️📬🎁
0

Adafruit IO without Libraries!
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Adafruit IO without Libraries!

by MotazBanyAmer on Fri Nov 22, 2019 11:33 am

Hi,
I'm trying to use Adafruit IO without Libraries, Just using AT Commands of my SIM808 module through GPRS.
I saw this is applicable to ThingSpeak, but couldn't do it with Adafruit IO.
the reason I don't want to use libraries is that I'm just building a prototype with Arduino, and Later I most likely to use ARM Controller, and I don't want to be stuck with Arduino libraries.

I looked into the resources, it's really confusing, I saw the method of creating a feed, it's available with cURL, and Arduino libraries. but I was not able to understand how to do it without the libraries.

thank you in advance

MotazBanyAmer
 
Posts: 2
Joined: Wed Nov 20, 2019 5:59 pm

Re: Adafruit IO without Libraries!

by abachman on Fri Nov 22, 2019 4:17 pm

Hi Motaz,


how to do it without the libraries


Are you looking for a guide to generating HTTP requests from scratch? What level of detail would be helpful?



- adam b.

abachman
 
Posts: 349
Joined: Mon Feb 01, 2010 12:48 pm

Re: Adafruit IO without Libraries!

by MotazBanyAmer on Sat Nov 23, 2019 4:20 pm

Yeah exactly
Actully would be great if you could give me detaild nerdy resources for the whole process :D
but would be good too if I had sufficient guide for doing the request from GPRS (im using SIM 808) with bare AT commands.
And thank you for your help sir

MotazBanyAmer
 
Posts: 2
Joined: Wed Nov 20, 2019 5:59 pm

Re: Adafruit IO without Libraries!

by abachman on Mon Nov 25, 2019 3:08 pm

Ah, hmm. If you haven't written raw HTTP requests from a bare TCP socket before, using any library is strongly recommended. If the Adafruit IO library works, use that for prototyping and switch to raw HTTP when you need to cross that bridge. Also, if you found a guide to publishing data to ThingSpeak "without any libraries", you should be able to use the same code to publish to IO with only minor changes. Do you happen to have a link to that guide?

IO will work with HTTP 1.0 requests and needs at least the Host, Content-Type, Content-Length, and X-AIO-Key headers. For example, this is a valid and complete HTTP request:
Code: Select all | TOGGLE FULL SIZE
POST /api/v2/test_username/feeds/my-sample-feed/data HTTP/1.0
Host: io.adafruit.com
Content-Type: application/json
Content-Length: 15
X-AIO-Key: b780002b85d6411ca0ad9f9c60195f72

{"value":"123"}



Note, because it's HTTP, each of those newlines must be \r\n instead of \n. The Content-Length of 15 is the length of the body of the request, {"value":"123"}, not including the newlines.

This is a complete and valid Ruby program that generates and sends a request on a raw TCP socket:
Code: Select all | TOGGLE FULL SIZE
require 'socket'
require 'json'

client = TCPSocket.new 'io.adafruit.com', 80

io_username = 'a_real_account'
io_key = 'totallyfakekey19'
io_feed = 'temperature'

data = {
  value: "80.30"
}

body = JSON.generate(data)

request =  "POST /api/v2/#{io_username}/feeds/#{io_feed}/data HTTP/1.0\r\n"
request += "Host: io.adafruit.com\r\n"
request += "Content-Type: application/json\r\n"
request += "Content-Length: #{body.size}\r\n"
request += "X-AIO-Key: #{io_key}\r\n\r\n"
request += body
request += "\r\n\r\n"

client.print request
client.close_write

while line = client.read
  puts line
  break if line.empty?
end


I'm not familiar with writing code for a cellular device. You'll have to look up your device's documentation for opening and writing bytes to TCP sockets.


- adam b.

abachman
 
Posts: 349
Joined: Mon Feb 01, 2010 12:48 pm

Please be positive and constructive with your questions and comments.