Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postmaster doesn't correctly support DOWNLOAD event, making http POSTS impossible. #15

Open
facultymatt opened this issue Jun 20, 2014 · 4 comments

Comments

@facultymatt
Copy link
Contributor

To send an http POST request using the gprs module, the user must enter the following AT commands:

AT+SAPBR=1,1
AT+HTTPINIT
AT+HTTPPARA="CID",1
AT+HTTPPARA="URL","https://posttestserver.com/post.php"
AT+HTTPACTION=1
AT+HTTPDATA=100,4000
// rest is truncated...

Lets focus on the last command listed:AT+HTTPDATA=100,4000. In this case, 100 is the size of the data to be sent via POST and 4000 is the time requested (in milliseconds) to send the data.

Executing this command replies with DOWNLOAD. At this point the user should begin sending their POST data. However, the postmaster doesn't return success in this case, making it impossible to start sending data -- instead it waits until the command errors out, sending the ERROR reply. The user never has a chance to send any data.

Below is stack from postmaster in debug mode:

AT+HTTPDATA=1,4000          
got command [ 'AT+HTTPDATA=1,4000' ]
sent [ 'AT+HTTPDATA=1,4000' ] on uart [ { parity: 0, readable: true, dataBits: 3, stopBits: 0, baudrate: 15200, writable: true, _events: { data: [ [Function] ] }, uartPort: 2 } ]
got a packet with AT+HTTPDATA=1,4000, 
starts: [ 'AT+HTTPDATA=1,4000' ] 
enders: [ 'OK', 'ERROR', '> ' ]
adding [ 'AT+HTTPDATA=1,4000' ] to the RXQueue
got a packet with DOWNLOAD, 
starts: [ 'AT+HTTPDATA=1,4000' ] 
enders: [ 'OK', 'ERROR', '> ' ]
adding [ 'DOWNLOAD' ] to the RXQueue
got a packet with ERROR, 
starts: [ 'AT+HTTPDATA=1,4000' ] 
enders: [ 'OK', 'ERROR', '> ' ]
adding [ 'ERROR' ] to the RXQueue
    ---> Found ERROR in enders:
 [ 'OK', 'ERROR', '> ' ] 
Emitting a post with:
 [ 'AT+HTTPDATA=1,4000', 'DOWNLOAD', 'ERROR' ]
@facultymatt
Copy link
Contributor Author

OK, so this is partially solved:

The Postmaster can be initialized with a custom array, I've changed this line to read

self.postmaster = new Postmaster(self.packetizer, ['OK', 'ERROR', '> ', 'DOWNLOAD']);

This works. However the next challenge is that when I send data, I get a reply of OK and this doesn't trigger a success. This is difficult to wrap my head around, and I'm not exactly sure how the starts / enders/ check works in Postmaster.

Heres a stack, I've send the command matt after the DOWNLOAD prompt

matt
got command [ 'matt' ]
sent [ 'matt' ] on uart [ { parity: 0, readable: true, dataBits: 3, stopBits: 0, baudrate: 15200, writable: true, _events: { data: [ [Function] ] }, uartPort: 2 } ]
got a packet with OK, 
starts: [ 'matt' ] 
enders: [ 'OK', 'ERROR', '> ', 'DOWNLOAD' ]

reply:
err:     { message: 'no reply after 10000 ms to message "matt"', type: 'timeout', name: 'Error', stack: 'stack traceback:
    /app/node_modules/gprs-sim900/postmaster.js:159: in function </app/node_modules/gprs-sim900/postmaster.js:103>' } 
data:

When I send the command AT+HTTPDATA=2,4000, for example, the chip replies got a packet with AT+HTTPDATA=2,4000. However when I send the command matt in response to DOWNLOAD the chip replies got a packet with OK. This seems to be causing the error... so the Postmaster must check that the command matches the packet?

Overall this isn't such a big deal because any custom commands would likely use _chain() and custom expectations, in which case you could expect ['matt', 'OK'] for the above example. However on the command line demo this breaks things, and in general I believe the Postmaster success check should be more flexible to support this case.

@ekolker
Copy link
Member

ekolker commented Jul 9, 2014

Again, can you give this a try with the newest code on master and see if it's still blocked?

@mweber-ovt
Copy link

facultymatt, I don't know if you are still working on this. In any case, in your code, the HTTPDATE must come first, and you write the data to the modem. Then, HTTPACTION transmits them.

@mweber-ovt
Copy link

facultymatt, I also want to thank you for mentioning posttestserver. That helped me A LOT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants