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

Send data from UltrasonicSensor readings to the Adafruit feed. Attach trigger to the feed, for triggering IFTTT WebHook in case of critical values. #13

Open
andrisole92 opened this issue Nov 15, 2017 · 32 comments

Comments

@andrisole92
Copy link
Collaborator

andrisole92 commented Nov 15, 2017

Collect and analyze the data from the Ultrasonic Sensor:

  • Set up notifications from IFTTT, when something is wrong (e.g. not enough water in the bucket)
  • Probably do the same thing with other sensors.
  • Possibly collect the daily or hourly data and log them to Adafruit.io?
@andrisole92 andrisole92 changed the title Collect and analyse the data from Ultrasonic Sensor. Collect and analyse the data from the Ultrasonic Sensor. Nov 15, 2017
@layerzerolabs
Copy link
Collaborator

Good start - as this issue is related to #10 I suggest you keep an eye of that issue and make sure as those improvements are developed your code uses them (helps us reduce merge conflicts when it comes to pull requests). Small things - can you assign yourself to this issue and add the labels enhancement (as it's not a bug) and esp32 - helps us keep track of stuff. Ta!

@andrisole92
Copy link
Collaborator Author

Hi @layerzerolabs, okay. Have installed and tested Ultrasonic sensor. Now I see, what the problem is. It seems not to have many errors when the distance is less than 35 cm. And after 35cm the measurements can be wrong.

@XenoXilus
Copy link
Collaborator

@layerzerolabs @hamishcunningham What's the typical deployment environment? Would the ultrasonic sensor ever be put in a scenario where it would be trying to make readings of more than 35cm?

@layerzerolabs
Copy link
Collaborator

layerzerolabs commented Nov 19, 2017 via email

@hamishcunningham
Copy link
Owner

I seem to remember (and in the context of #10 ) that we had trouble getting the timing right for the fire-wait-read cycle on these sensors, and also that they tended to interfere with each other in some way, and that I coded some hacks to get around this...

@andrisole92
Copy link
Collaborator Author

Do you remember where they are? If I can look at them, I can probably keep them in mind when coding solution or simply reuse them.

@layerzerolabs
Copy link
Collaborator

I've found that previously we used a 35ms delay just after reading each level sensor to ensure that they didn't interfere with each other - I suspect this might not be an issue with only one sensor but you could try it and report back?

@layerzerolabs
Copy link
Collaborator

As this issue is closely related to #10 I suggest that this issue focuses on passing data to IFTTT and using that to trigger notifications, collect other sensor data and possibly log to adafruit IO - leaving #10 to focus on producing a clean value from the ultrasonics?

@andrisole92
Copy link
Collaborator Author

Hi @layerzerolabs , I have just tested IFTT and Adafruit. It seems like adafruit can send email notifications without IFTT? And is it right thing to create a new feed for each new sensor/IoT devicei?

@layerzerolabs
Copy link
Collaborator

Hello - yes but following the survey in lecture 4 it seems that most people wanted notifications using a dedicated app. IFTTT offers this but Adafruit maybe only email or a couple of other options... So unless you can find another way, IFTTT seems to have a role alongside Adafruit IO, one for notifications and the other for logging & dashboard.
In terms of how to organise things, I think one feed per sensor makes most sense to me.

@andrisole92
Copy link
Collaborator Author

andrisole92 commented Nov 23, 2017

Okay. I see 2 ways of doing it:

  1. Setting up a trigger for every feed, so that it triggers a certain URL (e.g. IFTTT WebHook). The problem is, that I can't pass any parameters such as device id with the trigger from adafruit.io.
  2. Use already existing applets on IFTTT, but then I will have to create a new applet for every feed, and I have for example 1000 feeds it seems problematic.

@layerzerolabs
Copy link
Collaborator

I found this: https://learn.adafruit.com/using-ifttt-with-adafruit-io/ifttt-to-adafruit-io-setup# which implies you can set up an IFTTT 'recipe' to monitor an adafruit feed - you can then use that to trigger a notification on the IFTTT app which can be parametised.' Please could you review and see if this might be a route you could use?

@andrisole92
Copy link
Collaborator Author

@layerzerolabs , yeah, I have seen that. The problem is that one applet (service) is created manually for only one feed. If I had 1000 sensors, I would have to create 1000 applets manually, which is.... Not smart?

@layerzerolabs
Copy link
Collaborator

OK, yes now I understand that was your second option. I suppose when we need to scale we will need to find a provider with an API or host our own... In the meantime we need a solution for a single waterelf that can pass parameters to notifications... other IOT platforms are available like dweet.io. Your call if you want to do more research and discover a better way of achieving the goals of data logging and parametised notifications or accept the limitations of adafruit/IFTTT.

@andrisole92
Copy link
Collaborator Author

andrisole92 commented Nov 24, 2017

Actually, probably, I will be able to set up a WebHook on IFTTT, with URL, and then trigger this URL using HTTP GET method with parameters such as deviceID. URL will be triggered from io.adafruit.com using a trigger, that can be created programmatically using APIs.

In this case, one WebHook can work for the number of devices.

@andrisole92
Copy link
Collaborator Author

One thing to decide on, is what to use as an unique feed id. Can I use a MAC address?

@layerzerolabs
Copy link
Collaborator

layerzerolabs commented Nov 24, 2017

Yes, for non sensitive applications like this initially I think good choice. Perhaps combine name and MAC address together so humans can recognise it more easily? And thinking about human readability - can you edit this issue so it better reflects the scope and assign yourself to it please? ta!

@andrisole92 andrisole92 self-assigned this Nov 27, 2017
@andrisole92 andrisole92 changed the title Collect and analyse the data from the Ultrasonic Sensor. Send data from UltrasonicSensor readings to the Adafruit feed. Attach trigger to the feed, for triggering IFTTT WebHook in case of critical values. Nov 27, 2017
@andrisole92
Copy link
Collaborator Author

Okay, done.
Then it will something like USWE-MAC. (UltraSonic WaterElf)

@andrisole92
Copy link
Collaborator Author

andrisole92 commented Nov 27, 2017

Hi @layerzerolabs,
I am just wondering, is it necessary so that IFTTT is triggered by Adafruit.io? Or directly from the source?

By the way, triggers stopped working for some reasons on my Adafriut.io. I can't create any, and some 10, that I have created before just disappeared.

@andrisole92
Copy link
Collaborator Author

I am also getting a bad char[] concatenation using strcat, like this: "USWE-A89E0CC40A2⸮". With the question mark at the end.

@Eroc33
Copy link
Collaborator

Eroc33 commented Nov 27, 2017

@andrisole92 if you are using strcat are you making sure you a) have enough space in the destination buffer (I would recommend using strncat instead of strcat because of this), and b) the argument strings/buffers are correctly null terminated?

@andrisole92
Copy link
Collaborator Author

Thanks, @Eroc33 , my first char[] was too small. So, it works now!

@layerzerolabs
Copy link
Collaborator

I suppose we could trigger IFTTT directly - but that would mean sending two messages from the ESP32 - there is always the chance one could get lost, then the two systems would be out of sync... So my vote is for triggering via adafruit. But if you can make a case for the other way round then do, once the code is outlined we can review and collaborate on it, then you can implement collective best way forward?

@layerzerolabs
Copy link
Collaborator

Also really good to see @Eroc33 helping others - impressive grasp of C - nice one! Probably deserves a cut of my wages...

@andrisole92
Copy link
Collaborator Author

Hi @layerzerolabs ,

Actually, there is a benefit triggering IFTTT directly - you will know the exact value of the feed, instead of receiving a message, that value is higher than the threshold.

  1. I have crashed Adafruit.io Triggering system on my account. I am not sure I can continue doing that. I can write to the support, but it can take them a week to process and fix it.

@andrisole92
Copy link
Collaborator Author

@layerzerolabs ,
I think I am mostly done.

I have created 6 methods:

  1. bool createAdafruitFeedForUltraSonicSensor(String = "undefined"); - Creates new Feed on Adafruit.io. The problem is that methods AdafruitIO_Feed->exists() and AdafruitIO_Feed->create() does not work for some reason and the whole thing halts if using them. So, there were 2 options: use API directly, which would take a lot of time again. Or simply save any value. I have chosen to save 0, so that feed is being created indeed. It is might be better to use APIs, but I feel I need to leave some time for the dissertation report, which is due Monday. The first parameter is the feed name. If the name is not given, the method will return false. The method should return false if it was not possible to save the first value as well.
  2. bool triggerIFTTWebHook(String = ""); - simply triggers URL on IFTTT. The first parameter is URL params (e.g. stock=3&username=andrisole)
  3. bool createAdafruitIOTrigger(String, String = "gt", int = UltraSonicTriggerValue); - Creates trigger for the Adafruit IO feed. First parameter Feed ID, the second parameter is the operator (e.g gt for greater or sm for smaller). Can't find a proper documentation.
  4. String genrateIFTTTWebHookURL(String, String); - generates IFTTT WebHook URL, first parameter - event name, the second is IFTTT Key.
  5. String generateUltraSonicFeedName(); - Generates String in format USWE-MAC_ADDRESS
  6. String getAdafruitIOFeedId(String = ""); - Returns the feed id. The first parameter is a feed name.

I would like to say, that I feel like triggering IFTTT URL directly might be a bit better. I can check response code to see if my response got through.

I have also done some code work on IFTTT for the WebHook, so the email looks like:

screenshot_32

@layerzerolabs
Copy link
Collaborator

Hmm, I see that you are managing the whole process from the device using the API's - bravo - but perhaps a mixed approach of clicking in the web page to create feeds, triggers etc and then using them with the device would be simpler? Also can you give a really simple overview of what's going on - maybe walk through what happens during startup and then each loop?

@andrisole92
Copy link
Collaborator Author

Hi @layerzerolabs,
Yeah, sure.

The only thing, that needs to be created manually and configured is and IFTTT WebHook. It is a simple URL, that I need to trigger in order to receive an e-mail(SMS and other services can be added as well).

IFTTT WebHook typically takes 3 parameters, which should be named value1, value2, and value3. This is very useful because I can send device ID and the value, so in case of 1000s of devices, I am able to identify which one has gone wrong.

Now about feeds. I am not sure if manually creating feeds is productive. Adafruit has a good library and APIs for feeds, in case we need 1000s of them.

Well, it is a set of methods, that is not dependent on anything and I am trying to make them as transparent and reusable as possible.

@andrisole92
Copy link
Collaborator Author

I probably need to change createAdafruitFeedForUltraSonicSensor to createAdafruitFeed.

@layerzerolabs
Copy link
Collaborator

That approach to methods sounds very clean, so long as you can bring it all together then great, bear in mind the opposite concern of solving tomorrows problems today, premature optimisation/generalisation etc.Sounds good - looking forward to seeing how you orchestrate & documentation!

@andrisole92
Copy link
Collaborator Author

Hi @layerzerolabs ,

Sorry, my laptop died in the demo. I will update my pull request tonight, and some more points to the documentation.

I will also make a small demo in MyThing/Ex16.ino if that is fine?

@layerzerolabs
Copy link
Collaborator

layerzerolabs commented Dec 5, 2017 via email

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

No branches or pull requests

5 participants