Jump to content

Custom module not working


extrafresh
Go to solution Solved by extrafresh,

Recommended Posts

I have followed the tutorial here https://hak5.github.io/mk7-docs/docs/modules/modules/ to create a new module.

Firstly the documentation appears to be incorrect and I had to make changes to get the first 2 examples working.

The last example where a python script is used for the backend doesn't seem to work. It packages and uploads to the pineapple fine but the service for the module never seems to run. If I SSH onto the pineapple and run module.py manually everything works, but that doesn't happen automatically when I use the module.

Am I missing something obvious, or is there a step missing from the tutorial that covers this?

Link to comment
Share on other sites

I guess you have to be more detailed about what's not working to get some relevant response. Modules have been released over time based on that documentation and I haven't seen any real complaints, so it's difficult to guess what might be wrong.

Describe your work flow step by step and where the documentation/examples are failing by telling exactly what you're doing and reference the docs.

Your own module code is also good to see to be able to spot some eventual flaws in the implementation.

Link to comment
Share on other sites

Sorry, should have included that in the original post.

When I launch my module I get the busy spinner and I can see that the request is waiting for a response. Then after some time I get an error 500 with the message 'error: "start tries have been exceeded"'.

Whilst ssh'd onto the pineapple I can see that the module.py service is never running, whereas if I use a working module I can see that process running when I launch the module.

Here's the code I'm using.


someThing.component.html

<mat-card>
    <mat-card-title>Welcome to someThing</mat-card-title>
    <mat-card-content>
        <button mat-flat-button color="accent" (click)="doAThing();">
            Send the request
        </button>

        <br>
        <span>Response: {{apiResponse}}</span>
    </mat-card-content>
</mat-card>

 

someThing.component.ts

import { Component, OnInit } from '@angular/core';
import { ApiService } from '../services/api.service';

@Component({
    selector: 'lib-someThing',
    templateUrl: './someThing.component.html',
    styleUrls: ['./someThing.component.css']
})
export class someThingComponent implements OnInit {
    constructor(private API: ApiService) { }

    apiResponse = 'Do something';

    doAThing(): void {
        this.API.request({
            module: 'someThing',
            action: 'hello',
        }, (response) => {
            this.apiResponse = response;
        })
    }

    ngOnInit() {
    }
}

 

module.py

#!/usr/bin/env python3

import logging

from pineapple.modules import Module, Request

module = Module('someThing', logging.DEBUG)

@module.handles_action('hello')
def stuff(request):
    return 'Blah'

if __name__ == '__main__':
    module.start()

 

In terms of documentation that didn't work - one example is that the tutorial doesn't include that you have to use 

{{ apiResponse }}

in the html in order to render the response onto the page.

Link to comment
Share on other sites

  • Solution

I'd like to add that I've fixed the problem with a bit of luck.

The error was due to Windows line returns within my PyCharm project. There was no useful output on the pineapple or returned from the API to point me in that direction though, so if there is a good way to debug the loading of modules I would be very interested to know.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...