POST to Emoncms via GPRS - SIM900

Nice new forum folks, good work :slight_smile:

I’ve been working on posting data to EmonCMS using a SIM900 module, I have almost got it but failing at the last hurdle - I’m wondering if anyone here has managed to get this working and if so could I ask some questions on how you did it please? Thanks.

Thanks :slight_smile:

How far have you got? Please share your progress. I have not used this module but the process of posting to Emoncms (once you are connected to a network) should be the same as from any other device i.e. HTTP GET request

https://emoncms.org/site/api#input

Hi Glyn,

Thanks for getting back to me… below is the debug code which should show you the steps I’m taking to do this. I’m using the same POST process that I use happily via Ethernet - the one error on SAPBR=1,1 I think is fine as it establishes the GPRS connection but as I’m already connected it throws an error.

    Starting GPRS test
    TIME: 15:31:06 on 2016-05-27
    RTC : 1464363066
    SIM900 Reset
    --------------------------------
    Initialising SIM900

    AT
    OK

    AT+CREG?
    +CREG: 0,1
    OK

    AT+SAPBR=1,1
    ERROR

    AT+SAPBR=3,1,"CONTYPE","GPRS"
    OK

    AT+SAPBR=3,1,"APN","giffgaff.com"
    OK

    AT+SAPBR=3,1,"USER","GIFFGAFF"
    OK

    AT+SAPBR=3,1,"PWD","password"
    OK

    --------------------------------
    Sending Data

    AT+HTTPINIT
    OK

    AT+HTTPPARA="CID",1
    OK

    AT+HTTPPARA="URL","domain.co.uk"
    OK

    ---------------------------------
    Packet:      /emoncms/input/post.json?time=1464363125&node=GSM&json=CO2:430,iTA:20.85,iRH:75.19,iDP:25.74&apikey=eexxetc
    Post:        POST /emoncms/input/post.json?time=1464363125&node=GSM&json=CO2:430,iTA:20.85,iRH:75.19,iDP:25.74&apikey=eexxetc HTTP/1.1
    POST Length: 146
    ---------------------------------
    AT+HTTPDATA=146,10000
    DOWNLOAD
    OK

    AT+HTTPACTION=1
    OK
    +HTTPACTION:1,601,0

    AT+HTTPREAD
    OK

    AT+HTTPTERM
    OK

    --------------------------------
    SIGNAL
    Quality: 20
    Bars: Excellent
    --------------------------------

    AT
    OK

Hmmmm… getting a bit closer - there were some timing issues with my code, now when I post I get a response with the whole HTML code from the page www.mydomain/emoncms/input rather than a simple ‘OK’ - may I check the following please:

Server should be: mydomain.co.uk
HTTP should be: GET emoncms/input/post.json?json={power:200} HTTP/1.1

Also, do we need to add all the tags when making a GET or POST, IE Host, User-Agent etc?

Thanks.

No, the simplest request is probably:

https://emoncms.org/input/post.json?csv=100,200,300&apikey=xxxxx

Thanks, I’m still battling away at this - now trying the different TCP method but wondering how I know which port number to use? for POST HTTP/1.1 its 80, is it the same for TCP? Thanks.

Yes, use port 80 and ensure your request uses HTTP as opposed to HTTPS:

e.g. http://emoncms.org/input/post.json?csv=100,200,300&apikey=xxxxx

OK, this is what ended up working for me - it’s not the textbook method but has been quite stable in testing, hope this helps someone out:

AT
AT+SAPBR=3,1,“CONTYPE”,“GPRS”
AT+SAPBR=3,1,“APN”,“giffgaff.com
AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA=“CID”,1
AT+HTTPPARA=“URL”, “mydomain.com/input/post.json?json={power:200}&apikey=xxxxxxxxxxxxxxxxxxx4444444444444444xxxxxxxxx
AT+HTTPACTION=0

1 Like