Danyaal_Majid
Posts: 4
Joined: Mon Sep 18, 2023 2:55 am

An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 3:15 am

Hello Guys,

I find myself in a bit if a dilemma, i have to do a project using any model of the raspberry pi, but due to cost and lack of availability i have been unable to buy the necessary hardware, but the deadline for my course project is approaching near, and i need to test my code on a physical raspberry pi, as i have been unable to find one within my social and academic circle, i would be very thankful if one member of this community could test my code for me.

The only other piece of hardware my project requires is the Fingerprint Sensor By Adafruit. https://www.adafruit.com/product/751
or any other fingerprint sensor compatible with the

Code: Select all

adafruit-circuitpython-fingerprint
library.

It would be very helpful for me if one of the members has the hardware and are willing to test my code for me.

I understand that this is a very unusual request, so i hope i have not been rude.

I currently have not written the code, but within one day i will have the code ready, and if someone can acknowledge my request and remain on standby so that i have some peace of mind that my code will work properly, as the project only involves submission of the code, i do not necessarily have to show a hardware implementation.

Thanks all for understanding!

User avatar
B.Goode
Posts: 15433
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 7:18 am

Danyaal_Majid wrote:
Mon Sep 18, 2023 3:15 am
i have to do a project using any model of the raspberry pi, but due to cost and lack of availability i have been unable to buy the necessary hardware,

You can buy an RPiZeroW board in many places for 15 usd or equivalent right now.

If you didn't budget for the cost perhaps your academic institution has a hardship fund you could approach for help?

If you don't have to demonstrate working code, how will the people who mark the assignment be able to assess it?
Last edited by B.Goode on Mon Sep 18, 2023 7:32 am, edited 2 times in total.
Beware of the Leopard

Danyaal_Majid
Posts: 4
Joined: Mon Sep 18, 2023 2:55 am

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 7:28 am

Even Pi Zero is unavailable where I live, and 15 dollars is a lot of money for my location, for a single project buying a 45 dollar fingerprint sensor and 15 dollar was out of my budget, the project only calls for a sample implementation of the code, so I was hoping someone could test the code for me.

Is there any simulator available where I could test some python code? I have been unable to find any as of yet.

User avatar
B.Goode
Posts: 15433
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 7:34 am

Danyaal_Majid wrote:
Mon Sep 18, 2023 7:28 am
Even Pi Zero is unavailable where I live, and 15 dollars is a lot of money for my location, for a single project buying a 45 dollar fingerprint sensor and 15 dollar was out of my budget, the project only calls for a sample implementation of the code, so I was hoping someone could test the code for me.

Is there any simulator available where I could test some python code? I have been unable to find any as of yet.


https://trinket.io/



An approach that would show understanding of software development would be to develop your software on whatever hardware/OS platform you have available and implement mock interfaces to the API provided by the sensor supplier. This is what Adadfruit offer via Blinka to run their software on an OS.

The Adafruit software for this sensor is written for a microcontroller such as an Arduino, not for a microcomputer with an OS such as a Raspberry Pi. You could consider using an easily available and economical RPi Pico microcontroller instead.
Beware of the Leopard

Danyaal_Majid
Posts: 4
Joined: Mon Sep 18, 2023 2:55 am

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 7:42 am

Ok I understand what you are saying, how can I use this mock interface, because the only reason I am using a dev board like this is to interface with the fingerprint sensor, so if I can demonstrate that my program works as expected using a mock API, that would be great.

Just require assistance regarding the implementation of the mock API. I am currently using a windows PC, with a Linux VM also available.

My project basically has to read the fingerprint sensor, as well as a humidity and temp sensor from the RPi, and then implement a user auth system in django, where only authorized users are allowed to view the data from the sensors.

The Django web app can run on the pi or a PC the same, but I need a way to simulate the fingerprint and temp/humidity sensor.

Thanks for your support.

User avatar
B.Goode
Posts: 15433
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 8:40 am

I have nothing further to contribute.
Beware of the Leopard

dbrion1
Posts: 108
Joined: Tue May 30, 2023 4:42 pm
Location: North of France

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 10:22 am

I currently have not written the code, but within one day i will have the code ready, and if someone can acknowledge my request and remain on standby so that i have some peace of mind that my code will work properly, as the project only involves submission of the code, i do not necessarily have to show a hardware implementation.
Well, in France, in 2020, due to COVID, students who had to code for Arduino were given ... a link to simulators by their teachers.
It was the beginning of the popularity of wokwi (does not "only" simulates Arduini.. simulates picopi on micropython https://wokwi.com/projects/new/micropython-pi-pico (pity Django is not micropython....)).
Notice teachers helped students to find a simulator and were aware of the constraints (you have a money constraint, and maybe a card avalaibilty, too - if your teache is not aware of avalaibilties and prices, it would be useful to explain it- )

if your teacher does not want / cannot check full hardware, how does .s.he evaluate your work:

* knowing docucumentation and being able to summarize it?

* writing good quality python (pieces can "compile", quality checkers https://realpython.com/python-code-quality/#linters do not protest that much -I sometimes use flake8)?

* explaining code and hardware architecture.(essentially code)?

ghp
Posts: 3418
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 2:14 pm

A common way to test code without related hardware is to write a HAL, hardware abstraction layer class.
Here a small snipped just showing the basics. The Mock-class could just return some values as shown, or every 30secs change the string returned. Or build a tkinter GUI to set the return value for the mock class. Or a REST API which sets return value. Or something else.

Code: Select all

MOCK = True

# in programming languages supporting 'interface' this should be an interface
# unfortunateley python is not providing this 

class HAL:
    def read_fingerprint()->str:
        raise RuntimeException("not implemented")
    def get_temperature() -> float:
        raise RuntimeException("not implemented")
        
class ProductionHAL(HAL):
    def __init__(self):
        HAL.__init__(self)
        # instantiate the lib, setup bus connection, GPIO, whatever needed
        
    def read_fingerprint()->str:
        # invoke the sensor lib, read data, return value
        return "something"

class MockHAL(HAL):
    def __init__(self):
        HAL.__init__(self)
        # just an example for some mock data
        self.data=['a', 'b', 'c']
        self.idx = 0
    def read_fingerprint()->str:
        # invoke the sensor lib, read data, return value
        d = self.data[ self.idx]
        self.idx += 1
        self.idx %= len(self.data)
        
        return d

class HAL_Factory:
    @staticmethod
    def get_hal():
        if MOCK:
            return MockHAL()
        else:
            return ProductionHAL()
        
hal = HAL_Factory.get_hal()
print("hal available")

Last edited by ghp on Mon Sep 18, 2023 4:23 pm, edited 1 time in total.

User avatar
bensimmo
Posts: 6317
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 3:08 pm

If you want to, grab PiOS for x86, then you can use SenseHAT emulator to emulate humidity, temperature sensors and just use a joystick button to represent a finder print being checked, make the button present some 'data' that would be the fingerprint ID and check it allowed.

At its minimum, just ask every loop for a temp and pressure value and you can type the value in, it's just a number after all.


For more on the reader do a search, I think you can get USB ones so you just get sent a binary string, probably a hash code.
You could then pretend to have the reader but just have it pick from a list of supplies codes.

Fake it, in other words.

dbrion1
Posts: 108
Joined: Tue May 30, 2023 4:42 pm
Location: North of France

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 4:21 pm

At its minimum, just ask every loop for a temp and pressure value and you can type the value in, it's just a number after all.
Well, bensimmo and ghc helped you to spare 60 dollars (finger print and RPi);

If you want to have a more realistic value (not too realistic, in order not to mess fake values and real ones) you migh try the following thing (I bet you can get the local time, and deduce hour from it)
at 6 local (i.e. between 6 and 6h 59 )T = 20C; Hu = 80%
at 7 local (7, 20C, 80%)
then (8, 23, 50%), (9, 25, 40), (10, 30, 35%), (11, 35, 30), (12, 38, 30), (13, 40, 25), (14, 43, 20), (15, 40, 25) rising temperatures
afternoon (16, 38, 25), (17, 35, 30%) , (18, 30, 35), (19, 25, 40), (20, 23, 50)
night between 21 and 5) temperatre and humidity are constants 20C, 80%.
They are somewhat realistic: can happen in a very unpleasant summer day in Europe....
Notice : these fake temperatures are integers (most sensors give you 0.1 Celsius values); Fake humidities are integers, multiples of 5. ONCe you have manges to have all these fake valyes, no need to simulate sensor by typing.... (unpleasant, while debugging)

Danyaal_Majid
Posts: 4
Joined: Mon Sep 18, 2023 2:55 am

Re: An Unusual Issue, Need Someone to Test My Code.

Mon Sep 18, 2023 4:22 pm

Thanks everyone for their support, I will try to incorporate all of these solutions in my project.

Cheers.

Return to “Python”