Answer by taking a quote from the following article:

Jean-Jacques Rousseau (; French: [ZaZak Ruso]; 28 June 1712 - 2 July 1778) was a Genevan philosopher, writer, and composer of the 18th century, mainly active in France. His political philosophy influenced the Enlightenment across Europe, as well as aspects of the French Revolution and the overall development of modern political and educational thought. Rousseau's novel Emile, or On Education is a treatise on the education of the whole person for citizenship. His sentimental novel Julie, or the New Heloise was of importance to the development of pre-romanticism and romanticism in fiction.

After Rousseau's Emile had outraged the French parliament, an arrest order was issued by parliament against him, causing him to flee to Switzerland. Subsequently, when the Swiss authorities also proved unsympathetic to him--condemning both Emile, and also The Social Contract--Voltaire issued an invitation to Rousseau to come and reside with him, commenting that: "I shall always love the author of the 'Vicaire savoyard' whatever he has done, and whatever he may do...Let him come here [to Ferney]! He must come! I shall receive him with open arms. He shall be master here more than I. I shall treat him like my own son." Rousseau later expressed regret that he had not replied to Voltaire's invitation. In July 1762, after Rousseau was informed that he could not continue to reside in Bern, d'Alembert advised him to move to the Principality of Neuchatel, ruled by Frederick the Great of Prussia. Subsequently, Rousseau accepted an invitation to reside in Motiers, fifteen miles from Neuchatel. On 11 July 1762, Rousseau wrote to Frederick, describing how he had been driven from France, from Geneva, and from Bern; and seeking Frederick's protection. He also mentioned that he had criticized Frederick in the past and would continue to be critical of Frederick in the future, stating however: "Your Majesty may dispose of me as you like." Frederick, still in the middle of the Seven Years' War, then wrote to the local governor of Neuchatel, Marischal Keith who was a mutual friend of theirs: We must succor this poor unfortunate. His only offense is to have strange opinions which he thinks are good ones. I will send a hundred crowns, from which you will be kind enough to give him as much as he needs. I think he will accept them in kind more readily than in cash. If we were not at war, if we were not ruined, I would build him a hermitage with a garden, where he could live as I believe our first fathers did...I think poor Rousseau has missed his vocation; he was obviously born to be a famous anchorite, a desert father, celebrated for his austerities and flagellations...I conclude that the morals of your savage are as pure as his mind is illogical. Rousseau, touched by the help he received from Frederick, stated that from then onwards he took a keen interest in Frederick's activities. As the Seven Years' War was about to end, Rousseau wrote to Frederick again, thanking him for the help received and urging him to put an end to military activities and to endeavor to keep his subjects happy instead. Frederick made no known reply, but commented to Keith that Rousseau had given him a "scolding". CANNOTANSWER

What did he do there?

onwards he took a keen interest in Frederick's activities.