If it is setup to print via wi fi (not cable) then it will go through your router.
Have you changed any router settings or turned the router off?
If you are using Windows go to the printer settings and see if there is an option to change it from offline to online (you may need to right click on the printer icon).
If all else fails you may need to reinstall the printer. You probably got a book and CD when you got the printer so read the documentation and follow the instructions for reinstalling the printer.
Or go to the HP support web site where the documentation will be available online.
Here it is
http://support.hp.com/us-en/product/HP-Deskjet-2540-All-in-One-Printer-series/5295960/model/5295961