qunu / MMM-LoadShedding

0 stars 0 forks source link

Loadshedding schedule doesnt want to load. #1

Open FuryGear opened 1 year ago

FuryGear commented 1 year ago

Can we have an example of a working JavaScript and also the config code string.

I have my area id and url as well as my token key.

Regards

FG

qunu commented 1 year ago

Hi @FuryGear ,

This is my module settings in config.js

Running magicmirror version: 2.19.0

{
         module: "MMM-LoadShedding",
    header: "LOAD SHEDDING",
    position: "top_right"
},

Clone the repo into your MagicMirror/modules directory and restart MM

All the js needed is in https://github.com/qunu/MMM-LoadShedding/blob/main/MMM-LoadShedding.js, unless I'm not understanding your question?

qunu commented 1 year ago

@FuryGear

On line 48 of https://github.com/qunu/MMM-LoadShedding/blob/main/MMM-LoadShedding.js#L48 :

const urlApi = "http://192.168.3.91:8080/cors?url=https://developer.sepush.co.za/business/2.0/area?id=capetown-11-plumstead";

You will need to change 192.168.3.91:8080 to your Magic Mirror IP ADDRESS and PORT that it is running on as well as change capetown-11-plumstead to your area id.

This module only works with data responses from the service running at https://developer.sepush.co.za/business/2.0/area?id

Let me know if you need any other help

qunu commented 1 year ago

Will make an update soon to have the IP ADDRESS and PORT and AREA_ID set in the config.js

FuryGear commented 1 year ago

Thanks for responding.

I've done all that you have told me but still shows a back screen with no info. All my other modules pul info like the weather module.

Do I need to insert my token key somewhere?

On Tue, 25 Apr 2023, 12:51 qunu, @.***> wrote:

Will make an update soon to have the IP ADDRESS and PORT and AREA_ID set in the config.js

— Reply to this email directly, view it on GitHub https://github.com/qunu/MMM-LoadShedding/issues/1#issuecomment-1521582543, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7L2RBWSUFQOQMEJWNDSZI3XC6UEFANCNFSM6AAAAAAXIRH37E . You are receiving this because you were mentioned.Message ID: @.***>

qunu commented 1 year ago

There is a token needed in the header of the request, sorry I made a change in the /cors endpoint code on Magic Mirror. Let me find it and let you know. Totally forgot I made that change when I was trying to get the cross-origin request issues resolved

qunu commented 1 year ago

What version of MM are you running?

FuryGear commented 1 year ago

No problem, thanks!

On Tue, 25 Apr 2023, 16:23 qunu, @.***> wrote:

There is a token needed in the header of the request, sorry I made a change in the /cors endpoint code on Magic Mirror. Let me find it and let you know. Totally forgot I made that change when I was trying to get the cross-origin request issues resolved

— Reply to this email directly, view it on GitHub https://github.com/qunu/MMM-LoadShedding/issues/1#issuecomment-1521880482, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7L2RBWM6M7L7QDJLNWJCCTXC7M4TANCNFSM6AAAAAAXIRH37E . You are receiving this because you were mentioned.Message ID: @.***>

qunu commented 1 year ago

If you are using 2.22.0 or above then you should be able to pass the header based on below :

/**
 * A method that forewards HTTP Get-methods to the internet to avoid CORS-errors.
 *
 * Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
 *
 * Only the url-param of the input request url is required. It must be the last parameter.
 *
 * @param {Request} req - the request
 * @param {Response} res - the result
 */

So you change

const urlApi = "http://192.168.3.91:8080/cors?url=https://developer.sepush.co.za/business/2.0/area?id=capetown-11-plumstead";

to

const urlApi = "http://IP:PORT/cors?sendheaders=token:YOURTOKEN&url=https://developer.sepush.co.za/business/2.0/area?id=YOURID";

I haven't tested it as I haven't upgraded from 2.19.0 yet

FuryGear commented 1 year ago

OK cool. I will give that a go and then let you know if it works.

I'm am using the latest version of MM.

Really appreciate your help.

On Tue, 25 Apr 2023, 16:48 qunu, @.***> wrote:

If you are using 2.22.0 or above then you should be able to pass the header based on below :

/**

  • A method that forewards HTTP Get-methods to the internet to avoid CORS-errors.
  • Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
  • Only the url-param of the input request url is required. It must be the last parameter.
  • @param {Request} req - the request
  • @param {Response} res - the result */

So you change

const urlApi = " http://192.168.3.91:8080/cors?url=https://developer.sepush.co.za/business/2.0/area?id=capetown-11-plumstead ";

to

const urlApi = "http://IP:PORT/cors?sendheaders=token:YOURTOKEN&url= https://developer.sepush.co.za/business/2.0/area?id=YOURID";

I haven't tested it as I haven't upgraded from 2.19.0 yet

— Reply to this email directly, view it on GitHub https://github.com/qunu/MMM-LoadShedding/issues/1#issuecomment-1521924040, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7L2RBVXZHL5ZIJNRMMRKW3XC7P2NANCNFSM6AAAAAAXIRH37E . You are receiving this because you were mentioned.Message ID: @.***>

FuryGear commented 1 year ago

Good morning Qunu

So I made the change this morning as stated above but still no luck :-(

If I use the following command directly in my terminal it gets the schedule:

curl --location --request GET 'https://developer.sepush.co.za/business/2.0/area?id=ekurhuleni3-6-clayville' \ --header 'token: MY-TOKEN'

FuryGear commented 1 year ago

Ok. I got it working.

I changed my IP address to localhost:8080 and it pulled through.

Problem solved. Party time. Thanks Qunu

qunu commented 1 year ago

Awesome stuff. Send a pic of your running mirror display if you can.

FuryGear commented 1 year ago

Will do.

On Wed, 26 Apr 2023, 13:25 qunu, @.***> wrote:

Awesome stuff. Send a pic of your running mirror display if you can.

— Reply to this email directly, view it on GitHub https://github.com/qunu/MMM-LoadShedding/issues/1#issuecomment-1523255967, or unsubscribe https://github.com/notifications/unsubscribe-auth/A7L2RBV2WKSYLVJR6YSJJATXDEA2BANCNFSM6AAAAAAXIRH37E . You are receiving this because you were mentioned.Message ID: @.***>

aidan1010 commented 1 year ago

Hi there,

Where do I insert the API token?