Python or node

Can I write to blynk direct from my Python script? If yes are there any examples?

@Johnuready yes, study Blynk’s API at http://docs.blynkapi.apiary.io

Can I write direct from Python 2.7 using Python commands on my raspberry pi or do I need to write JavaScript?

With the API you should be able to interface directly.

Thanks for the above API reference. I’m trying to scope my blynk app to my Python Program. Am I right in saying that by running node I would unload all the overhead of running blynk through Python?

If that’s correct how do I pass data between Python and the node programs and

I take it I run the node and my Python programs at the same time on my raspberry pi?

Blynk’s API is automatically a low overhead system so it depends which language you prefer to use.

With nodejs child_process().

Yes

I kinda understand that the Raspberry pI users Node to communicate with Blynk.

I do not understand how to communicate with a Python program I have written on the Raspberry pi using the nodejs “child _process” as quoted above.

This is very frustrating as I’m beginning to think that lack of information on the net about using Python with Blynk I should look elsewhere for another remote app

I can find examples of how to connect with Node to the pi and use the gpio button (switch a gpio on and off) but nothing on the harder issues of using the virtual pin and passing data from a Python program. I have successfully added the simpler job of adding button on blynk and my Python program to watch for a gpio pin going hi.

Does anybody have simple instructions/examples for a novice programmer?

You are very unlikely to find an easier system that has so many features but you are free to look.

You haven’t actually said what you want to do.

If you search this site, or the wider internet, for child_process you will see examples of how it’s used. Basically it’s a way of running any script, like Python, from within nodejs.

What I need is a simple example of how to include in my Python code to write and read to the Virtual Pin. ie a Python line of code that would turn a LED on say on V1.

I hope with this basic example I should be able use other Widgets direct from Python code.

What do you think?

Try this… not a clue if it is what you are looking for, but it has the word python in it :stuck_out_tongue:

Thanks for that link. I’ll take that idea to my Raspberry pi group tomorrow and see what far better coders then me say, hopefully it’s going the right way. I will post the results.

My set up - Raspberry pi running Rasbian with Python 2.7

I still have some basic questions that I need to understand:

1 When I use the Authorisation code and register my device from the Terminal Command line on the pi am I using Nodejs?

2 When I toggle a gpio on my pi from blynk am i using nodejs on the pi?

3 Will I be using nodejs when I sort out how to write direct from the Python program to blynk?

Thanks

Yes to 1, 2 and 3 if you are just asking Blynk to run a Python sketch with child_process().

However Blynk does have a version for Python as per the link provided by @Gunner

I would say it’s not as well supported as their nodejs but that’s not particularly well supported either.

Easiest and best supported is ESP8266 with C++.

Depends on your coding skill set as to which route you should choose.

What exactly do you want to do “in Python”?

My Python program currently runs real time monitoring of ADC channels and switches gpio lines to configure external devices. Currently my pi is connected to blynk and I have configured the app button on gpio 12 to toggle back on the pi with my Python program checking for the pin going high and putting the pi program in sleep mode until released by pressing the button on the app. That was easy to follow U tube videos to complete and required no programming apart from Python.

Now I would like to sent information back from the Python program to the app like switching on led, and understanding a methodology to use the V pin.

I found this today using Python to run a “Butter Robot” with blynk.

https://hackaday.io/project/26038/logs?sort=newest

Could be a start?

Yes that’s a full Python implementation for Blynk and only runs to about 30 lines of code.

Looks like the “Butter Bot” example puts me on track to use Virtual Pins from app to python.

The other example below:

import BlynkLib
import time

BLYNK_AUTH = 'YourAuthToken'

**# Initialize Blynk**
blynk = BlynkLib.Blynk(BLYNK_AUTH)

**# Register Virtual Pins**
@blynk.VIRTUAL_WRITE(1)
def my_write_handler(value):
    print('Current V1 value: {}'.format(value))

@blynk.VIRTUAL_READ(2)
def my_read_handler():
    # this widget will show some time in seconds..
    blynk.virtual_write(2, time.ticks_ms() // 1000)

**# Start Blynk (this call should never return)
blynk.run()

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Is that a good start to send data to widgets?

Looks fine now it’s formatted :slight_smile:

The Python library, is it the lasted version?
I was getting errors back when using the write command. Any ideas?

It logged into the blynk server ok, looked to fail on a value the library didn’t recognise

I was Using the write command from my Raspberry Pi to turn an LED “on” on my iPhone app using data value 255

I back home tonight, I try and post the test code and errors soon.

Did you ever manage to post how you were able to run the above python script? Thanks!