Giter Club home page Giter Club logo

counterfit's Introduction

CounterFit

GitHub license GitHub contributors GitHub issues GitHub pull-requests PRs Welcome

GitHub watchers GitHub forks GitHub stars

The CounterFit logo

IoT is great fun, but has a downside - hardware. You need access to a range of devices such as sensors and actuators to build your IoT projects. Sometimes you might have these devices, other times you may not - maybe you are waiting for a delivery, or parts are out of stock, or they are too expensive.

That's where this tool comes in.

What is CounterFit

CounterFit is a tool that is designed to fake various IoT hardware components, such as LEDs, buttons, temperature sensors and the like, that you can then access from IoT device code running on your computer rather than on an IoT device. It is made of two parts:

  • The CounterFit app - this is a web app run locally where you can connect fake sensors and actuators to your virtual hardware
  • Shims - these are libraries that fake popular hardware APIs so you can take code that runs against well known hardware and run it against the CounterFit app.

This project is under construction

This project is seriously under construction! Please let me know if you want to help.

Under development animated GIF

Installing and running the app

  • Install the CounterFit app:

    pip install CounterFit
  • Run the app:

    counterfit
  • The app will launch, listening for web requests on port 5000, and open a web browser for you to start adding virtual sensors and actuators to your project

Running on a different port

To use a different port than the default 5000, set the --port option when you run the app:

counterfit --port 5050

Shims

The shims are designed to mimic the APIs for popular hardware components. The idea being you should be able to take code built against the shim and eventually run it on real hardware by changing the name of the package that is imported.

Available shims

Samples

Check out the samples directory for a range of samples.

counterfit's People

Contributors

achillfeeder avatar jsoref avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

counterfit's Issues

Unable to run CounterFit on VS Code

Hi, I have been trying to learn IoT and I found out about CounterFit. While it worked earlier on, it is not working now. Issue seems to be with a module under werkzeug. I have uninstalled and reinstalled the module along with its requirements. I am still unable to figure out the issue. Please help.

 (CodeIoT) D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Scripts>counterfit
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Scripts\counterfit.exe\__main__.py", line 4, in <module>
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\CounterFit\counterfit.py", line 11, in <module>
    from eventlet import event
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\eventlet\__init__.py", line 17, in <module>
    from eventlet import convenience
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\eventlet\convenience.py", line 7, in <module>
    from eventlet.green import socket
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\eventlet\green\socket.py", line 21, in <module>
    from eventlet.support import greendns
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\eventlet\support\greendns.py", line 45, in <module>
    from eventlet.green import ssl
  File "D:\Rohan S Gurumurthy\Coding\Python\IoT\CodeIoT\Lib\site-packages\eventlet\green\ssl.py", line 25, in <module>
    _original_wrap_socket = __ssl.wrap_socket
                            ^^^^^^^^^^^^^^^^^
AttributeError: module 'ssl' has no attribute 'wrap_socket'

Add camera support

Add support for a camera with a new sensor in the CounterFit app, and a shim for Picamera.

This would need to support the users camera, as well as image uploads.

Add all the Grove Py sensors

So far the Grove shim only has the light sensor and LED. It needs all the rest of the Grove sensors.

This will be a big chunk of work, as there are a lot, and this will need multiple new sensors and actuators added to the core CounterFit app. There's also considerations around screens, or sensors that detect multiple things (temperature, pressure and humidity for example).

https://github.com/Seeed-Studio/grove.py/tree/master/grove

unable to use the Counterfit library

Hi Team,

After installing the Counterfit library, I am getting below error
from werkzeug.urls import url_quote
ImportError: cannot import name 'url_quote' from 'werkzeug.urls' (/opt/homebrew/lib/python3.11/site-packages/werkzeug/urls.py)

I seems the url_quote function was available in versions of Werkzeug prior to version 2.0. However, it has been deprecated and removed in Werkzeug 2.0 and later versions.

CounterFit installation issue

Hi,

I'm trying to set up the CounterFit app however, getting the following error, and unable to proceed. I'm not sure if this is something related to the packages or python version it doesn't support.

Could you please see the below error snapshot and advise.

OS: Windows 10
Python Version : 3.11

(.venv) PS C:\nightlight> pip install CounterFit
Collecting CounterFit
Using cached CounterFit-0.1.4.dev6-py3-none-any.whl (119 kB)
Collecting Flask==2.1.2
Using cached Flask-2.1.2-py3-none-any.whl (95 kB)
Collecting Flask-SocketIO==5.2.0
Using cached Flask_SocketIO-5.2.0-py3-none-any.whl (17 kB)
Collecting eventlet==0.33.1
Using cached eventlet-0.33.1-py2.py3-none-any.whl (226 kB)
Collecting beautifulsoup4==4.9.3
Using cached beautifulsoup4-4.9.3-py3-none-any.whl (115 kB)
Collecting lxml==4.6.4
Using cached lxml-4.6.4.tar.gz (3.2 MB)
Preparing metadata (setup.py) ... done
Requirement already satisfied: soupsieve>1.2 in c:\nightlight.venv\lib\site-packages (from beautifulsoup4==4.9.3->CounterFit) (2.3.2.post1)
Collecting dnspython>=1.15.0
Using cached dnspython-2.2.1-py3-none-any.whl (269 kB)
Collecting greenlet>=0.3
Using cached greenlet-2.0.1-cp311-cp311-win_amd64.whl (191 kB)
Requirement already satisfied: six>=1.10.0 in c:\nightlight.venv\lib\site-packages (from eventlet==0.33.1->CounterFit) (1.16.0)
Collecting Werkzeug>=2.0
Using cached Werkzeug-2.2.2-py3-none-any.whl (232 kB)
Collecting Jinja2>=3.0
Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)
Collecting itsdangerous>=2.0
Using cached itsdangerous-2.1.2-py3-none-any.whl (15 kB)
Collecting click>=8.0
Using cached click-8.1.3-py3-none-any.whl (96 kB)
Collecting python-socketio>=5.0.2
Using cached python_socketio-5.7.2-py3-none-any.whl (56 kB)
Collecting colorama
Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Requirement already satisfied: MarkupSafe>=2.0 in c:\nightlight.venv\lib\site-packages (from Jinja2>=3.0->Flask==2.1.2->CounterFit) (2.1.1)
Collecting bidict>=0.21.0
Using cached bidict-0.22.1-py3-none-any.whl (35 kB)
Requirement already satisfied: python-engineio>=4.3.0 in c:\nightlight.venv\lib\site-packages (from python-socketio>=5.0.2->Flask-SocketIO==5.2.0->CounterFit) (4.3.4)
Installing collected packages: Werkzeug, lxml, Jinja2, itsdangerous, greenlet, dnspython, colorama, bidict, beautifulsoup4, python-socketio, eventlet, click, Flask, Flask-SocketIO, CounterFit
DEPRECATION: lxml is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at pypa/pip#8559
Running setup.py install for lxml ... error
error: subprocess-exited-with-error

× Running setup.py install for lxml did not run successfully.
│ exit code: 1
╰─> [96 lines of output]
Building lxml version 4.6.4.
Building without Cython.
Building against pre-built libxml2 andl libxslt libraries
running install
C:\nightlight.venv\Lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
creating build
creating build\lib.win-amd64-cpython-311
creating build\lib.win-amd64-cpython-311\lxml
copying src\lxml\builder.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\cssselect.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\doctestcompare.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\ElementInclude.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\pyclasslookup.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\sax.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\usedoctest.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml_elementpath.py -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml_init_.py -> build\lib.win-amd64-cpython-311\lxml
creating build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes_init_.py -> build\lib.win-amd64-cpython-311\lxml\includes
creating build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\builder.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\clean.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\defs.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\diff.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\ElementSoup.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\formfill.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\html5parser.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\soupparser.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html\usedoctest.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html_diffcommand.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html_html5builder.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html_setmixin.py -> build\lib.win-amd64-cpython-311\lxml\html
copying src\lxml\html_init_.py -> build\lib.win-amd64-cpython-311\lxml\html
creating build\lib.win-amd64-cpython-311\lxml\isoschematron
copying src\lxml\isoschematron_init_.py -> build\lib.win-amd64-cpython-311\lxml\isoschematron
copying src\lxml\etree.h -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\etree_api.h -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\lxml.etree.h -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\lxml.etree_api.h -> build\lib.win-amd64-cpython-311\lxml
copying src\lxml\includes\c14n.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\config.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\dtdvalid.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\etreepublic.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\htmlparser.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\relaxng.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\schematron.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\tree.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\uri.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xinclude.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xmlerror.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xmlparser.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xmlschema.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xpath.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\xslt.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes_init_.pxd -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\etree_defs.h -> build\lib.win-amd64-cpython-311\lxml\includes
copying src\lxml\includes\lxml-version.h -> build\lib.win-amd64-cpython-311\lxml\includes
creating build\lib.win-amd64-cpython-311\lxml\isoschematron\resources
creating build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\rng
copying src\lxml\isoschematron\resources\rng\iso-schematron.rng -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\rng
creating build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl
copying src\lxml\isoschematron\resources\xsl\RNG2Schtrn.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl
copying src\lxml\isoschematron\resources\xsl\XSD2Schtrn.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl
creating build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_abstract_expand.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_dsdl_include.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_message.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_schematron_skeleton_for_xslt1.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\iso_svrl_for_xslt1.xsl -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
copying src\lxml\isoschematron\resources\xsl\iso-schematron-xslt1\readme.txt -> build\lib.win-amd64-cpython-311\lxml\isoschematron\resources\xsl\iso-schematron-xslt1
running build_ext
building 'lxml.etree' extension
creating build\temp.win-amd64-cpython-311
creating build\temp.win-amd64-cpython-311\Release
creating build\temp.win-amd64-cpython-311\Release\src
creating build\temp.win-amd64-cpython-311\Release\src\lxml
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DCYTHON_CLINE_IN_TRACEBACK=0 -Isrc -Isrc\lxml\includes -IC:\nightlight.venv\include -IC:\Users\anil.mishra\AppData\Local\Programs\Python\Python311\include -IC:\Users\anil.mishra\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /Tcsrc\lxml\etree.c /Fobuild\temp.win-amd64-cpython-311\Release\src\lxml\etree.obj -w
cl : Command line warning D9025 : overriding '/W3' with '/w'
etree.c
src\lxml\etree.c(288): fatal error C1083: Cannot open include file: 'longintrepr.h': No such file or directory
Compile failed: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe' failed with exit code 2
creating Users
creating Users\ANIL1.MIS
creating Users\ANIL
1.MIS\AppData
creating Users\ANIL1.MIS\AppData\Local
creating Users\ANIL
1.MIS\AppData\Local\Temp
"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -I/usr/include/libxml2 "-IC:\Program Files (x86)\Microsoft Visual
Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\VS\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\cppwinrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" /TcC:\Users\ANIL1.MIS\AppData\Local\Temp\xmlXPathInitmxxtxnre.c /FoUsers\ANIL1.MIS\AppData\Local\Temp\xmlXPathInitmxxtxnre.obj
xmlXPathInitmxxtxnre.c
C:\Users\ANIL~1.MIS\AppData\Local\Temp\xmlXPathInitmxxtxnre.c(1): fatal error C1083: Cannot open include
file: 'libxml/xpath.h': No such file or directory
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.34.31933\bin\HostX86\x64\cl.exe' failed with exit code 2
*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> lxml

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

Thanks

Running CounterFit in Dev Container

I am trying to use CounterFit in Dev Container as part of IoT-For-Beginners course. So idea is to run all course using virtual hardware but not directly on local PC but rather in docker container.

Here is a "Hello World" code I am trying to run:

from counterfit_connection import CounterFitConnection
CounterFitConnection.init('127.0.0.1', 5000)
print('Hello World!')

Here is output of the run:

vscode ➜ .../1-introduction-to-iot/code/virtual-device/nightlight (main ✗) $ python app.py 
Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
    raise err
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connectionpool.py", line 398, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connection.py", line 239, in request
    super(HTTPConnection, self).request(method, url, body=body, headers=headers)
  File "/usr/local/python/lib/python3.10/http/client.py", line 1282, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/local/python/lib/python3.10/http/client.py", line 1328, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/local/python/lib/python3.10/http/client.py", line 1277, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/local/python/lib/python3.10/http/client.py", line 1037, in _send_output
    self.send(msg)
  File "/usr/local/python/lib/python3.10/http/client.py", line 975, in send
    self.connect()
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connection.py", line 205, in connect
    conn = self._new_conn()
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7f400832dc00>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/python/lib/python3.10/site-packages/requests/adapters.py", line 440, in send
    resp = conn.urlopen(
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "/usr/local/python/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /connect (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f400832dc00>: Failed to establish a new connection: [Errno 111] Connection refused'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/workspaces/IoT-For-Beginners/1-getting-started/lessons/1-introduction-to-iot/code/virtual-device/nightlight/app.py", line 3, in <module>
    CounterFitConnection.init('127.0.0.1', 5000)
  File "/usr/local/python/lib/python3.10/site-packages/counterfit_connection.py", line 42, in init
    requests.post(CounterFitConnection.base_url + 'connect')
  File "/usr/local/python/lib/python3.10/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/python/lib/python3.10/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/python/lib/python3.10/site-packages/requests/sessions.py", line 529, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/python/lib/python3.10/site-packages/requests/sessions.py", line 645, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/python/lib/python3.10/site-packages/requests/adapters.py", line 519, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /connect (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f400832dc00>: Failed to establish a new connection: [Errno 111] Connection refused'))
vscode ➜ .../1-introduction-to-iot/code/virtual-device/nightlight (main ✗) $ 

It's worth while saying that if I try to run simple Web server inside of the same container, using same 5000 port, it runs just fine.

Any idea what might be a problem?

Update `lxml` to 4.6.4 or higher (missing wheels for Python 3.10)

Hi!

I came here from the Microsoft IoT course.
I wanted to use a virtual device, but installing CounterFit fails with the following error:

*********************************************************************************
Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?
*********************************************************************************
  • OS: Windows 10
  • Python version: 3.10.4

Before that I had a missing Visual Studio build tools error, I downloaded them, but now the error above occurs.

After some research I found out that lxml==4.6.3 tries to install lxml from source - streamlink/streamlink#4100 (comment)
The same issue discussion also says that lxml==4.6.4 fixes this problem - streamlink/streamlink#4100 (comment)

Could you please update lxml in setup.py, so that it's possible to install CounterFit without compiling lxml from source?

Thanks in advance 😄

Error handling

Add error handling.

For example, return an error if a request is made to a pin that is not configured. This error should be returned from the app and raised in the shim.

Run CounterFit in docker container

Before writing a PR to make CounterFit work in docker--is there any reason NOT to do so? It looks like all of the emulation happens through the socket through the CounterFit library.

I've already patched a container to work as well--I'm now testing with some of the sensors and actuators to make sure it doesn't inhibit functionality.

I also recognize that it's fairly easy to get started with CounterFit and you'd need the same packages installed whether or not it runs in docker. My specific use case is that I setup a number of virtualenvs and want to simplify the process by orchestrating a container (one line and simpler install vs two lines + installation).

Running Error In Windows 10

Hi,
I'm using python 3.10.7 and I've installed counterfit, counterfit-connection and counterfit-shims-grove on a virtual environment. But on running counterfit on the terminal I get the error AttributeError: module 'dns.rdtypes' has no attribute 'ANY'. How can I solve this?

Could someone tell me how to use this tool in the Windows system?

I tried to install Counterfit in the Windows system using pip install, with Python version 3.11, but I'm not quite clear on what it means to launch the application. I tried using the command 'counterfit' in PowerShell, but the system tells me it cannot recognize 'counterfit' as the name of a cmdlet, function, script file, or operable program. Please check the spelling of the name, and if it includes a path, make sure the path is correct and try again.

Set up actions

Set up the following actions:

  • Test on PR
  • Lint and black check on PR
  • Automated build on main
  • Automated deploy on main

Problem running counterfit Ubuntu

Hi,

Until today I was able to install and run counterfit on my VM Ubuntu 20.04 with python3.8.10.

Today after a successful counterfit installation (pip install CounterFit) when I try to run it I get the following error:

ubuntu@ubunu2004:$ counterfit
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/counterfit", line 5, in
from CounterFit.counterfit import main
File "/home/ubuntu/.local/lib/python3.8/site-packages/CounterFit/counterfit.py", line 9, in
from eventlet import event
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/init.py", line 17, in
from eventlet import convenience
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/convenience.py", line 7, in
from eventlet.green import socket
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/green/socket.py", line 21, in
from eventlet.support import greendns
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/support/greendns.py", line 66, in
setattr(dns, pkg, import_patched('dns.' + pkg))
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/support/greendns.py", line 61, in import_patched
return patcher.import_patched(module_name, **modules)
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/patcher.py", line 132, in import_patched
return inject(
File "/home/ubuntu/.local/lib/python3.8/site-packages/eventlet/patcher.py", line 109, in inject
module = import(module_name, {}, {}, module_name.split('.')[:-1])
File "/home/ubuntu/.local/lib/python3.8/site-packages/dns/zone.py", line 86, in
class Zone(dns.transaction.TransactionManager):
File "/home/ubuntu/.local/lib/python3.8/site-packages/dns/zone.py", line 757, in Zone
) -> dns.rdtypes.ANY.SOA.SOA:
AttributeError: module 'dns.rdtypes' has no attribute 'ANY'
ubuntu@ubunu2004:$

Can I get some help solving this issue?

Thanks.

.NET

Are there any plans to release a .NET version of this?

在ubuntu和 windows,运行counterfit,出现importError

C:\Users\13197>counterfit
Traceback (most recent call last):
File "f:\python\lib\runpy.py", line 192, in _run_module_as_main
return run_code(code, main_globals, None,
File "f:\python\lib\runpy.py", line 85, in run_code
exec(code, run_globals)
File "F:\Python\Scripts\counterfit.exe_main
.py", line 5, in
File "f:\python\lib\site-packages\CounterFit\counterfit.py", line 14, in
from flask import Flask, request, render_template
File "f:\python\lib\site-packages\flask_init
.py", line 7, in
from .app import Flask as Flask
File "f:\python\lib\site-packages\flask\app.py", line 27, in
from . import cli
File "f:\python\lib\site-packages\flask\cli.py", line 17, in
from .helpers import get_debug_flag
File "f:\python\lib\site-packages\flask\helpers.py", line 14, in
from werkzeug.urls import url_quote
ImportError: cannot import name 'url_quote' from 'werkzeug.urls' (f:\python\lib\site-packages\werkzeug\urls.py)

root@root:~/桌面/CounterFit-main$ counterfit
Traceback (most recent call last):
File "/home/zengsihao/.local/bin/counterfit", line 5, in
from CounterFit.counterfit import main
File "/home/zengsihao/.local/lib/python3.10/site-packages/CounterFit/counterfit.py", line 14, in
from flask import Flask, request, render_template
File "/home/zengsihao/.local/lib/python3.10/site-packages/flask/init.py", line 7, in
from .app import Flask as Flask
File "/home/zengsihao/.local/lib/python3.10/site-packages/flask/app.py", line 27, in
from . import cli
File "/home/zengsihao/.local/lib/python3.10/site-packages/flask/cli.py", line 17, in
from .helpers import get_debug_flag
File "/home/zengsihao/.local/lib/python3.10/site-packages/flask/helpers.py", line 14, in
from werkzeug.urls import url_quote
ImportError: cannot import name 'url_quote' from 'werkzeug.urls' (/home/zengsihao/.local/lib/python3.10/site-packages/werkzeug/urls.py)

unable to run app.py

when I run single command counterfit ,it will work,but I run python app.py,it give me many bugs below.
I don't know what happen,I change the port ,but it still not work,can you tell me how to fix it,thanks

F:\vsworkspace\hamony-ts>python app.py
Traceback (most recent call last):
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connection.py", line 203, in _new_conn
sock = connection.create_connection(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
raise err
File "E:\tools\anaconda3\Lib\site-packages\urllib3\util\connection.py", line 73, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connectionpool.py", line 791, in urlopen
response = self._make_request(
^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connectionpool.py", line 497, in _make_request
conn.request(
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connection.py", line 395, in request
self.endheaders()
File "E:\tools\anaconda3\Lib\http\client.py", line 1289, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "E:\tools\anaconda3\Lib\http\client.py", line 1048, in _send_output
self.send(msg)
File "E:\tools\anaconda3\Lib\http\client.py", line 986, in send
self.connect()
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connection.py", line 243, in connect
self.sock = self._new_conn()
^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connection.py", line 218, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x000002400396FC90>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "E:\tools\anaconda3\Lib\site-packages\requests\adapters.py", line 486, in send
resp = conn.urlopen(
^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\urllib3\connectionpool.py", line 845, in urlopen
retries = retries.increment(
^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\urllib3\util\retry.py", line 515, in increment
raise MaxRetryError(_pool, url, reason) from reason # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /connect (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002400396FC90>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "F:\vsworkspace\hamony-ts\app.py", line 2, in
CounterFitConnection.init('127.0.0.1', 5000)
File "E:\tools\anaconda3\Lib\site-packages\counterfit_connection.py", line 42, in init
requests.post(CounterFitConnection.base_url + 'connect')
File "E:\tools\anaconda3\Lib\site-packages\requests\api.py", line 115, in post
return request("post", url, data=data, json=json, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\requests\api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\requests\sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\requests\sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\tools\anaconda3\Lib\site-packages\requests\adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=5000): Max retries exceeded with url: /connect (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002400396FC90>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.