Attempting to do post request but with empty object


#1

Hi guys!

For our application, we need to POST data from the resin device to our servers, each time the temperature sensor got updated with a new temperature mark.

To POST the results out, we’re using the request npm package (https://www.npmjs.com/package/request).

Every time the temperature changes, the post function is activated, and a new entry is saved in our DB, which is a mLab add-on in Heroku. The only problem is that the entry is empty; it’s a simple empty {} javascript object…

What may be causing this? Thanks in advance for any help!!

EDIT: Using the same parameters, but using Postman, works as well.


#3

Hi @arthurborges! As you’ve seen by using Postman, there’s nothing in resin that would prevent a POST request from working correctly – I suspect you’ve run into bug in your code somewhere


#4

Hi @chrischabot!

Understood, I’ll search for bugs, then.

Do you know a way to debug resin code fast? Each thing I change I must go through the same long process: git push resin master, then wait for the build to run in resin.io, then see in console the output of my logs…then change a thing and have to repeat the whole process.


#5

Ah yeah that can be a slow and frustrating process at times @arthurborges – One of the things that can help a lot is our local development mode, it’ll take a bit of getting used to the flow, but does speed the cycles up a lot:

In cases where what I’m debugging is not device / hardware dependent, I sometimes also use ResinOS-in-Docker so that the disk io, cpu and memory are all limited by your development workstation, and not the lower power system on chip type of device: https://github.com/resin-os/resinos-in-container

Between those two I suspect development will become a whole lot more pleasant :slight_smile:


#6

Oh and a final tip, make sure your COPY statement for the NodeJS source code is as far to the bottom of the Dockerfile.template as possible – Docker creates a layer for each COPY and RUN command in there, and will rebuild only the modified layers, and everything that’s layered on top of that.

One trick for node for instance is copy your package.json and run the npm install for it before the COPY command for the rest of your source code, that way it will use the cached layer for all the node modules installation when you modify your javascript files.


#7

Ok, I’ll follow it up! Thanks again for the tips and help! =)


#8

I’ve found the bug. Was a mis-ordering function. The variable declaration was called later than the function. Rookie error, but glad we could solved it!


#9

@arthurborges great to hear! And let me know how the local development works out for you, we’re always happy to get feedback